The WHERE clause filters a result set to include only records that meet a specified condition.
The following SQL statement selects all customers from “Mexico” in the “Customers” table:
SELECT * FROM Customers WHERE Country=‘Mexico’; |
In SQL, single quotes are required around text values (although many database systems also accept double quotes), while numeric fields should not be enclosed in quotes.
SELECT * FROM Customers WHERE CustomerID=1; |
Note: The WHERE clause is not limited to SELECT statements; it is also used in UPDATE, DELETE statements, etc.!
The following operators can be utilized in the WHERE clause:
Operator |
Description |
= |
Equal |
<> |
Not equal. Note: In certain SQL versions, this operator may be represented as != |
> |
Greater than |
< |
Less than |
>= |
Greater than or equal |
<= |
Less than or equal |
BETWEEN |
Between a specified range. |
LIKE |
Search for a pattern. |
IN |
To specify multiple potential values for a column. |