Logical Operators

The logical operators are: NOT, AND, and OR.

You can use the logical operator NOT to negate a predicate. For example:
NOT ZIPCODE = 90023
You can connect predicates with the logical operators AND and OR:
AREACODE = 213 AND ZIPCODE = 90021 OR ZIPCODE = 90022

The order of precedence for the logical operators is:

  1. NOT
  2. AND
  3. OR.

In the preceding example, the statement is true when AREACODE = 213 and ZIPCODE = 90021 or when ZIPCODE = 90022, regardless of the value of AREACODE.

By using parentheses, you can override this order. If you want to select data only when AREACODE equals 213 and ZIPCODE equals either 90021 or 90022, you can code:
AREACODE = 213 AND (ZIPCODE = 90021 OR ZIPCODE = 90022)
Because the AND is evaluated before the OR, this is equivalent to:
AREACODE = 213 AND ZIPCODE = 90021 OR ZIPCODE = 90022 AND AREACODE = 213