Weird predicate syntax in queries

M

MikeB

Why, when I create a query in Access with the design view does Access
put so many brackets in the WHERE clause?

eg.:

SELECT Count(Games.GameNumber) AS [Rated Games]
FROM Games
WHERE (((Games.White)=[Player?]) AND ((Games.Rated)=True)) OR
(((Games.Rated)=True) AND ((Games.Black)=[Player?]));


Isn't this syntactically the same as:

SELECT Count(Games.GameNumber) AS [Rated Games]
FROM Games
WHERE (Games.Rated=True) AND (Games.White=[Player?] OR
Games.Black=[Player?]);

If I open a query in the design view, Access keeps changing the WHERE
syntax and it bothers me.

I'm having a hard time wrapping my head around the set theory of SQL
queries.
 
D

Douglas J. Steele

Yes, the two queries are the same.

Not really sure why Access insists on putting so many parentheses.
 
J

John W. Vinson

Why, when I create a query in Access with the design view does Access
put so many brackets in the WHERE clause?

eg.:

SELECT Count(Games.GameNumber) AS [Rated Games]
FROM Games
WHERE (((Games.White)=[Player?]) AND ((Games.Rated)=True)) OR
(((Games.Rated)=True) AND ((Games.Black)=[Player?]));


Isn't this syntactically the same as:

SELECT Count(Games.GameNumber) AS [Rated Games]
FROM Games
WHERE (Games.Rated=True) AND (Games.White=[Player?] OR
Games.Black=[Player?]);

Yes. I've never understood the program's madness for extra parentheses. They
can be deleted without harm, and if you save the query from the SQL window and
avoid opening it in the query grid window, it will keep your changes
(usually).
If I open a query in the design view, Access keeps changing the WHERE
syntax and it bothers me.

I'm having a hard time wrapping my head around the set theory of SQL
queries.

The way a WHERE clause works can be understood using "Boolean Algebra" -
something I was lucky enough to learn way before I got into databases, about
1962 in fact. The AND and OR operators work like + and - operators in
arithmatic, with rigid logical rules. If the WHERE clause evaluates to TRUE
then the record is retrieved; if it evaluates to FALSE (or to NULL), the
record will be excluded.

Sets and the notorious Venn diagrams (overlapping circles showing set
membership) are another way of visualizing the actions of Boolean logic.
 
M

MikeR

MikeB said:
Why, when I create a query in Access with the design view does Access
put so many brackets in the WHERE clause?

eg.:

SELECT Count(Games.GameNumber) AS [Rated Games]
FROM Games
WHERE (((Games.White)=[Player?]) AND ((Games.Rated)=True)) OR
(((Games.Rated)=True) AND ((Games.Black)=[Player?]));


Isn't this syntactically the same as:

SELECT Count(Games.GameNumber) AS [Rated Games]
FROM Games
WHERE (Games.Rated=True) AND (Games.White=[Player?] OR
Games.Black=[Player?]);

If I open a query in the design view, Access keeps changing the WHERE
syntax and it bothers me.

I'm having a hard time wrapping my head around the set theory of SQL
queries.

Being picky, [] are brackets, () are parentheses. ;-)
MikeR
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top