Using AND, NOT, and OR connectives to create complex conditions
What cities and districts are located in the southern or western regions?
SELECT hq_city, district, region FROM aroma.market WHERE region = 'South' OR region = 'West';
|New Orleans||New Orleans||South|
|San Jose||San Francisco||West|
|San Francisco||San Francisco||West|
|Los Angeles||Los Angeles||West|
To refine the selecting of rows, search conditions can be joined and the order of evaluation can be forced. A search condition specifies a condition that is "true," "false," or "unknown" about a given row. The result of a search condition is derived by application of the specified logical operators (AND, OR, NOT) to the result of each specified predicate. If logical operators are not specified, the result of the search condition is the result of the specified predicate. AND and OR are defined in the following table, which P and Q are any predicates:
|P||Q||P AND Q||P OR Q|
NOT(true) is false, NOT(false) is true, and NOT(unknown) is unknown.
Search conditions within parentheses are evaluated first. If the order of evaluation is not specified by parentheses, NOT is applied before AND, and AND is applied before OR. The order in which operators at the same precedence level are evaluated is undefined to allow for optimization of search conditions.