NOT IN

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Tests whether an expression differs from every row returned by a subquery. Returns a boolean result.

Syntax 

1<expression> NOT IN ( <subquery> )

Arguments 

Required 

  • <expression>: The left-hand value to evaluate and compare against each row of the subquery result.
  • <subquery>: A parenthesized subquery that returns exactly one column.

Returns 

Returns true if only unequal subquery rows are found, including when the subquery returns no rows. Returns false if an equal row is found.

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

Considerations 

  • The subquery must return exactly one column.
  • NOT IN is equivalent to <> ALL.
  • To avoid unexpected results, filter out NULL values in your subquery (for example, WHERE column IS NOT NULL). A single NULL can cause the entire expression to return NULL instead of TRUE.

Examples 

Exclude Subquery Results 

Return rows whose value does not appear in the subquery result.

1SELECT col1
2FROM tab1
3WHERE col1 NOT IN (SELECT col2 FROM tab2 WHERE col2 IS NOT NULL);

Related Documentation