WHERE clause
The WHERE clause defines the filters that will be applied to the data. This allows you to select only the part of the data you are interested in. Logically, the WHERE clause is applied immediately after the FROM clause.
Examples
-
Select rows from the table of capitals where the value of
countryis'Italy':SELECT * FROM capitals WHERE country = 'Italy';+---------+---------+ | country | capital | +---------+---------+ | Italy | Rome | +---------+---------+ -
Let’s select from the table of days of the week the rows that match the given case-sensitive
LIKEclause:SELECT * FROM weekdays WHERE name LIKE '%S%';+--------+----------+ | number | name | +--------+----------+ | 6 | Saturday | +--------+----------+ | 7 | Sunday | +--------+----------+ -
Let’s select from the table of days of the week the rows that match the given
ILIKEclause, which is case insensitive:SELECT * FROM weekdays WHERE name ILIKE '%S%';+--------+-----------+ | number | name | +--------+-----------+ | 2 | Tuesday | +--------+-----------+ | 3 | Wednesday | +--------+-----------+ | 4 | Thursday | +--------+-----------+ | 6 | Saturday | +--------+-----------+ | 7 | Sunday | +--------+-----------+ -
Let’s select all rows corresponding to the given compound expression:
SELECT * FROM weekdays WHERE number > 5 OR number = 3;+--------+-----------+ | number | name | +--------+-----------+ | 3 | Wednesday | +--------+-----------+ | 6 | Saturday | +--------+-----------+ | 7 | Sunday | +--------+-----------+