Logical Operators

The logical operators are AND, OR, and NOT. The logical operators AND and OR are used to connect search conditions in WHERE clauses.

AND joins two or more conditions and returns results only when all the conditions are true. For example, the following query finds only the rows in which the author's last name is Ringer and the author's first name is Anne. It will not find the row for Albert Ringer.

SELECT *
FROM authors
WHERE au_lname = 'Ringer' AND au_fname = 'Anne'

OR also connects two or more conditions, but it returns results when any of the conditions is true. The following query searches for rows containing Anne or Ann in the au_ fname column:

SELECT *
FROM authors
WHERE au_fname = 'Anne' OR au_fname = 'Ann'