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, column2FROM table_nameWHERE condition;The examples use the Productions table from SQL Select.
Matching text
Section titled “Matching text”To list only the productions made in the UK:
SELECT Title, FormatFROM ProductionsWHERE 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.
Comparing numbers
Section titled “Comparing numbers”Numbers take no quotes. To find the productions with a budget under five million:
SELECT Title, BudgetFROM ProductionsWHERE Budget < 5000000;| Title | Budget |
|---|---|
| Saltmarsh | 3,900,000 |
| Fennick’s Return | 850,000 |
Comparison operators
Section titled “Comparison operators”| 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.