SQL AND & OR

The SQL AND & SQL OR keywords are used together with the SQL WHERE clause to join two or more search conditions specified in the WHERE clause. Let's use the weather table to illustrate how to use SQL AND & SQL OR keywords:

CityAverageTemperatureDate
New York22 C10/10/2005
Seattle21 C10/10/2005
Washington20 C10/10/2005
New York18 C10/09/2005
Seattle20 C10/09/2005
Washington17 C10/09/2005

Here is how to select all rows where the city is either Washington or New York:

SELECT * FROM Weather WHERE City = 'Washington' OR City = 'New York'

The result of this SQL OR expression will be:

CityAverageTemperatureDate
New York22 C10/10/2005
Washington20 C10/10/2005
New York18 C10/09/2005
Washington17 C10/09/2005

The following SQL statement using the SQL AND keyword will select all dates on which the average temperature in Washington was greater than 18 C:

SELECT Date FROM Weather WHERE City = 'Washington' AND AverageTemperature > 18

Here is the result of this SQL AND expression:

Date
10/10/2005