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 customers who live in Ontario, Manitoba, or Quebec, you can enter this query:
SELECT CompanyName, State FROM Customers 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 CompanyName, State FROM Customers WHERE State IN( 'ON', 'MB', 'PQ');
Perhaps the most important use for the IN keyword is in nested queries, also called subqueries.
|Discuss this page in DocCommentXchange.
Send feedback about this page using email.
|Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1|