To recap what was covered in Chapter 6, Querying a Single Table, here are the logical operators: AND, OR, NOT, IN, LIKE, and BETWEEN. Logical operators evaluate to true (or 1), false (or 0), or NULL.
Some example use cases of logical operators are listed here:
- WHERE column1 <> 1 AND column2 = 2—This will return all rows where column does not equal 1 and where column2 equals 2.
- WHERE column1 <> 1 OR column2 = 2—This will return all rows where column does not equal 1 OR where column2 equals 2.
- WHERE column1 IN (1, 2, 3)—This will return all rows where column1 values are equal to 1, 2, or 3.
- WHERE column1 BETWEEN 1 AND 4—This will return all rows where column1 values are between 1 and 4, including 1 and 4.
- WHERE column1 ...