SQL AND, OR, NOT
Combine conditions.
SQL AND, OR and NOT Operators
The WHERE clause can be combined with AND, OR, and NOT operators.
The AND and OR operators are used to filter records based on more than one condition:
- The AND operator displays a record if all the conditions separated by AND are TRUE.
- The OR operator displays a record if any of the conditions separated by OR is TRUE.
The NOT operator displays a record if the condition(s) is NOT TRUE.
AND Example
The following SQL statement selects all fields from "Customers" where "Country" is "Germany" AND "City" is "Berlin":
SELECT * FROM Customers
WHERE Country = 'Germany' AND City = 'Berlin';
OR Example
The following SQL statement selects all fields from "Customers" where "City" is "Berlin" OR "München":
SELECT * FROM Customers
WHERE City = 'Berlin' OR City = 'München';
NOT Example
The following SQL statement selects all fields from "Customers" where "Country" is NOT "Germany":
SELECT * FROM Customers
WHERE NOT Country = 'Germany';