SQL Language Guide : 4. Elements of SQL Statements : SQL Operators : Logical Operators
 
Share this page                  
Logical Operators
SQL has three logical operators, shown in order of precedence:
NOT
AND
OR
Use parentheses to change the order of evaluation. For example, the following expression:
exprA OR exprB AND exprC
is evaluated as:
exprA OR (exprB AND exprC)
When parentheses are used as follows:
(exprA OR exprB) AND exprC
the DBMS Server evaluates (exprA OR exprB) first, then uses the AND operator for the result with exprC.
Parentheses can also be used to change the default evaluation order of a series of expressions combined with the same logical operator. For example, the following expression:
exprA AND exprB AND exprC
is evaluated as:
(exprA AND exprB) AND exprC
To change this default left-to-right grouping, use parentheses as follows:
exprA AND (exprB AND exprC)
The parentheses direct the DBMS Server to use the AND operator for exprB and exprC, then use the AND operator for that result with exprA.