Previous Topic

Next Topic

SQL IN Extended Comparison Operator

The IN extended comparison operator indicates if a value exists in a set of values. The syntax is:

value [NOT] IN (value_set)

Use the IN extended comparison operator to filter a table based on the existence of a field value in a specified set of comparison values. The set of comparison values can be a comma-separated list of field names, literals, or calculated values. The following example returns all Customers where the Country field is either 'NZ' or 'AU':

SELECT A.CustomerCode, A.CountryCode FROM ARCUST A WHERE (A.CountryCode IN ('NZ', 'AU'))

The value to compare with the values set can be any or a combination of: a field value, a literal value, or a calculated value.

Use NOT to return the converse of an IN comparison.

IN can be used with all non-BLOB data types, but all values compared must be of the same or a compatible data type.

IN is useful when filtering to retrieve rows with non-contiguous values. For filtering to retrieve rows with contiguous values that fall within a specified range, use the BETWEEN extended comparison operator.

See Also

SQL Extended Comparison Operators

Book Contents

Book Index