Skip to content

SQL Where

WHERE filters rows. The database tests a condition against each row, keeps the rows where it holds, and leaves the rest out of the result.

SELECT column1, column2
FROM table_name
WHERE condition;

The examples use the Productions table from SQL Select.

To list only the productions made in the UK:

SELECT Title, Format
FROM Productions
WHERE Country = 'UK';
Title Format
The Lantern Keepers Drama series
Quarry Lane Feature film
Six Bells Drama series

Text values go in single quotes. Some databases accept double quotes too, but single quotes work in all of them.

Numbers take no quotes. To find the productions with a budget under five million:

SELECT Title, Budget
FROM Productions
WHERE Budget < 5000000;
Title Budget
Saltmarsh 3,900,000
Fennick’s Return 850,000
Operator Keeps a row when the value is
= equal to the one given
<> not equal to it; many databases also accept !=
> greater than it
< less than it
>= greater than or equal to it
<= less than or equal to it
BETWEEN inside a range, ends included
LIKE a match for a text pattern
IN one of a list of values

BETWEEN, LIKE and IN each have a page of their own.