IN predicate
The IN predicate compares a value or values with a collection of values.
The fullselect must identify a number of columns that is the same as the number of expressions specified to the left of the IN keyword (SQLSTATE 428C4). The fullselect may return any number of rows.
- An IN predicate of the form:
is equivalent to a basic predicate of the form:expression IN expression
expression = expression
- An IN predicate of the form:
is equivalent to a quantified predicate of the form:expression IN (fullselect)
expression = ANY (fullselect)
- An IN predicate of the form:
is equivalent to a quantified predicate of the form:expression NOT IN (fullselect)
expression <> ALL (fullselect)
- An IN predicate of the form:
is equivalent to:expression IN (expressiona, expressionb, ..., expressionk)
where fullselect in the values-clause form is:expression = ANY (fullselect)
VALUES (expressiona), (expressionb), ..., (expressionk)
- An IN predicate of the form:
is equivalent to a quantified predicate of the form:(expressiona, expressionb,..., expressionk) IN (fullselect)
Note that the operand on the left side of this form of these predicates is referred to as a row-value-expression.(expressiona, expressionb,..., expressionk) = ANY (fullselect)
The values for expression1 and expression2 or the column of fullselect1 in the IN predicate must be compatible. Each field of the row-value-expression and its corresponding column of fullselect2 in the IN predicate must be compatible. The rules for result data types can be used to determine the attributes of the result used in the comparison.
The values for the expressions in the IN predicate (including corresponding columns of a fullselect) can have different code pages. If a conversion is necessary, the code page is determined by applying rules for string conversions to the IN list first, and then to the predicate, using the derived code page for the IN list as the second operand.
Examples
DEPTNO IN ('D01', 'B01', 'C01')
EMPNO IN (SELECT EMPNO FROM EMPLOYEE WHERE WORKDEPT = 'E11')
Example 3: Given the following information, this example evaluates to true if the specific value in the row of the COL_1 column matches any of the values in the list:
Expressions | Type | Code Page |
---|---|---|
COL_1 | column | 850 |
HV_2 | host variable | 437 |
HV_3 | host variable | 437 |
CON_1 | constant | 850 |
COL_1 IN (:HV_2, :HV_3, CON_4)
the two host variables
will be converted to code page 850, based on the rules for string
conversions. YEAR(EMENDATE) IN (YEAR(CURRENT DATE),
YEAR(CURRENT DATE - 1 YEAR),
YEAR(CURRENT DATE - 2 YEARS))
(ID, DEPT) IN (SELECT MANAGER, DEPTNUMB FROM ORG)