IN and NOT IN

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Compares an expression against a list of values. Returns a boolean result.

Syntax 

1<expression> IN ( <value>, ... )
2<expression> NOT IN ( <value>, ... )

Arguments 

Required 

  • <expression>: The left-hand value to compare.
  • <value>, ...: A parenthesized list of scalar expressions. The left-hand value is compared against each expression in the list.

Returns 

IN returns true if the left-hand value equals any value in the list, and false otherwise. NOT IN returns true if the left-hand value is unequal to every value in the list—a shorthand for expression <> value1 AND expression <> value2 AND ....

Returns NULL if the left-hand expression is NULL, or if there are no equal right-hand values and at least one right-hand value is NULL.

Considerations 

  • The right-hand side is a parenthesized list of scalar expressions, not a subquery. For the subquery forms, see IN and NOT IN.
  • To avoid unexpected NULL results with NOT IN, ensure the value list contains no NULL values.

Examples 

Match Against a List 

1SELECT col1
2FROM tab1
3WHERE col1 IN ('a', 'b', 'c');

Exclude a List 

1SELECT col1
2FROM tab1
3WHERE col1 NOT IN (1, 2, 3);

Related Documentation