OVERVIEW   1 FROM   2 SELECT   3 WHERE   4 GO BACK   ←

SQL: WHERE

The WHERE keyword is used when it is necessary to filter out specific data. It adds conditions which records must meet in order to be included in the query. The following query displays all of the records in the students table.

SELECT *

FROM students;

id last_name first_name grade
001 Holmes Guy 88
002 Atwell James 73
003 O'Hara Alice 96
004 Peterson Holly 83

If, however, we only want to see the records of those students with a grade greater than 85, the WHERE keyword is required.

SELECT *

FROM students

WHERE grade > 85;

id last_name first_name grade
001 Holmes Guy 88
003 O'Hara Alice 96

The students with grades of 85 and less are now excluded from the query results.

The keywords AND and OR can be used after WHERE to make the query even more specified. Their usage can be seen in the following interactive query. Click on the grayed out sections to add or remove them from the query.

SELECT *

FROM countries

WHERE population > 1000000 AND language = 'Spanish' OR language = 'Icelandic';

name capital language population
Spain Madrid Spanish 47350000
Iceland Reykjavík Icelandic 366425
Peru Lima Spanish 32000000
Vietnam Hanoi Vietnamese 97340000
BACK