ANY / SOME

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Tests whether a comparison between an expression and any row of a subquery is true. Returns a boolean result. SOME is a synonym for ANY.

Syntax 

1<expression> <operator> ANY ( <subquery> )
2<expression> <operator> SOME ( <subquery> )

Arguments 

Required 

  • <expression>: The left-hand value to evaluate and compare against each row of the subquery result.
  • <operator>: A comparison operator that returns a boolean result that’s applied between the left-hand expression and each subquery row.
  • <subquery>: A parenthesized subquery that returns exactly one column.

Returns 

Returns true if the comparison yields true for any subquery row. Returns false if no true result is found, including when the subquery returns no rows.

Returns NULL if no comparison returns true and at least one right-hand row yields NULL for the operator’s result.

Considerations 

  • The subquery must return exactly one column.
  • IN is equivalent to = ANY.

Examples 

Compare Against Any Subquery Row 

Return rows whose value is greater than at least one value in the subquery result.

1SELECT col1
2FROM tab1
3WHERE col1 > ANY (SELECT col2 FROM tab2);

Empty Subquery Result 

When the subquery returns no rows, ANY returns false.

1SELECT 1 = ANY (SELECT col2 FROM tab2 WHERE 1 = 0) AS result;

Returns false.

NULL in the Subquery Result 

When no row matches and at least one row is NULL, the result is NULL rather than false.

1SELECT 1 = ANY (VALUES (2), (3), (NULL)) AS result;

Returns NULL.

Related Documentation