Connecting conditions with logical operators

The logical operators AND, OR, and NOT are used to connect search conditions in WHERE clauses. When more than one logical operator is used in a statement, AND operators are normally evaluated before OR operators. You can change the order of execution with parentheses.

Using AND

The AND operator joins two or more conditions and returns results only when all of the conditions are true. For example, the following query finds only the rows in which the contact's last name is Purcell and the contact's first name is Beth.

SELECT *
   FROM Contacts
   WHERE GivenName = 'Beth'
      AND Surname = 'Purcell';
Using OR

The OR operator connects two or more conditions and returns results when any of the conditions is true. The following query searches for rows containing variants of Elizabeth in the GivenName column.

SELECT *
   FROM Contacts
   WHERE GivenName = 'Beth'
      OR GivenName = 'Liz';
Using NOT

The NOT operator negates the expression that follows it. The following query lists all the contacts who do not live in California:

SELECT *
   FROM Contacts
   WHERE NOT State = 'CA';