Parentheses

If you use both AND and OR, use parentheses to specify the order that AND and OR conditions are evaluated. Compare the following examples:

With parentheses:

WHERE (JOB='SALES' AND COMM > 1200) OR YEARS > 10

Selects employees that satisfy at least one of these conditions:

Result: 90, 260, 310, 340.

With the parentheses moved:

WHERE JOB='SALES' AND (COMM > 1200 OR YEARS > 10)

Selects employees that satisfy both these conditions:

Result: 90, 310, 340.

You can use more than one level of parentheses. The condition is evaluated from the innermost level of nested parentheses outward, as in algebraic expressions.

If you do not use parentheses, all conditions connected by AND are evaluated and connected first, and then conditions connected by OR. That is, if A, B, and C are conditions, these two phrases produce the same results.

     A AND B OR C    means     (A AND B) OR C
[ Previous Page | Next Page | Contents | Index ]