English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Usage and examples of the SQL WHERE keyword

SQL Keyword Reference

SELECT

The WHERE command filters the result set to query records that meet the specified conditions.

The following SQL statement selects all customers from the 'Mexico' in the 'Customers' table:

SELECT * FROM Customers
WHERE Country='Mexico';

SQL requires single quotes around text values (most database systems also allow the use of double quotes).

However, do not enclose numeric fields in quotes:

SELECT * FROM Customers
WHERE CustomerID=1;

Note: The WHERE clause is not only used in SELECT statements, but also in UPDATE, DELETE statements, and so on!

The following operators can be used in the WHERE clause:

Operator
Description
=Equal
<>

Not Equal. Note: In some versions of SQL, this operator can be written as !=

>Greater Than
<Less Than
>=Greater Than or Equal to
<=Less Than or Equal to
BETWEENBetween Ranges
LIKESearch Pattern
INSpecify Multiple Possible Values for a Column

SQL Keyword Reference