The IN
predicate checks whether a value or a value list is contained in a specified set of values or value lists.Syntax
<in_predicate> ::=
<expression> [NOT] IN <subquery>
| <expression> [NOT] IN <expression_list>
| <expression_list> [NOT] IN <subquery>
| <expression_list> [NOT] IN (<expression_list>,...)
Explanation
The subquery must supply a result table (see
result table name) that contains the same number of columns as the number of values specified by the expression on the left-hand side of the IN operator.Each value list specified on the right-hand side of the IN operator must contain the same number of values as specified in the value list on the left-hand side of the IN operator.
The entry '------' in the list below means that no statement can be made if only the result of the comparison with one s is known.
Result of the function x IN S |
|
x=s is true for at least one s |
true |
x=s is true for all s |
true |
S contains NULL values and x=s is true for the remaining s |
true |
S is empty |
false |
x=s is false for at least one s |
------ |
x=s is false for all s |
false |
S contains NULL values and x=s is false for the remaining s |
undefined |
x=s is not true for any s and is undefined for at least one value s |
undefined |
x NOT IN S
has the same result as NOT(x IN S)Model table:
customerChoosing all customers who are natural persons (not companies):
SELECT title, firstname, name, city FROM customer
WHERE title IN ('Mr','Mrs')
TITLE |
FIRSTNAME |
NAME |
CITY |
Mrs |
Jenny |
Porter |
New York |
Mr |
Martin |
Porter |
Los Angeles |
Mrs |
Sally |
Peters |
Los Angeles |
Mr |
Peter |
Brown |
Hollywood |
Mr |
Michael |
Porter |
New York |
Mr |
George |
Howe |
New York |
Mr |
Frank |
Randolph |
Los Angeles |
Mr |
Joseph |
Peters |
Los Angeles |
Mrs |
Susan |
Brown |
Los Angeles |
Mr |
Anthony |
Jackson |
Los Angeles |
Mr |
Thomas |
Adams |
Los Angeles |
Mr |
Mark |
Griffith |
New York |
Mrs |
Rose |
Brown |
Hollywood |