Contents Index Using ranges (between and not between) in the WHERE clause Matching character strings in the WHERE clause

ASA SQL User's Guide
  Queries: Selecting Data from a Table
    The WHERE clause: specifying rows

Using lists in the WHERE clause


The IN keyword allows you to select values that match any one of a list of values. The expression can be a constant or a column name, and the list can be a set of constants or, more commonly, a subquery.

For example, without in, if you want a list of the names and states of all the contacts who live in Ontario, Manitoba, or Quebec, you can type this query:

SELECT company_name , state
FROM customer
WHERE state = 'ON' OR state = 'MB' OR state = 'PQ'

However, you get the same results if you use IN. The items following the IN keyword must be separated by commas and enclosed in parentheses. Put single quotes around character, date, or time values. For example:

SELECT company_name , state
FROM customer
WHERE state IN( 'ON', 'MB', 'PQ')

Perhaps the most important use for the IN keyword is in nested queries, also called subqueries.


Contents Index Using ranges (between and not between) in the WHERE clause Matching character strings in the WHERE clause