System information
About SQL 35
Using the SQL WHERE clause to limit the rows returned
To conditionally select data from a table, you can add a WHERE clause to the SELECT
statement, which results in the following syntax:
SELECT column_name FROM table_name WHERE column condition value
With the WHERE clause, you can use any of the following operators:
For example, to select the columns named LastName and FirstName for Clients whose City is
Boston, use the following SELECT statement:
SELECT LastName, FirstName FROM Clients Where City = 'Boston'
The result of the preceding SQL statement contains the following data:
You can compose a WHERE clause with one or more conditions; these are called subclauses. You
join subclauses using the operators AND and OR. The AND operator displays a row if all
conditions that are listed are True. The OR operator displays a row if any of the conditions listed
are True. The following statement shows an example of a WHERE clause with multiple
subclauses:
SELECT LastName, FirstName FROM Clients Where City = 'Boston' AND FirstName =
'Marie'
Operator Description
=Equal
<> Not equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive range
AND Joins one or more conditions
OR Joins one or more conditions
LIKE Specifies a search for a pattern in a column. You can use a percent sign
(%) to define wildcards (missing letters in the pattern) before and after the
pattern.
LastName FirstName
Brown Marie
Adams Russell