ANY and ALL are comparison modifiers used with subqueries. They let you compare a single scalar expression to a set of values returned by a subquery.- ANY (or its synonym SOME) evaluates the comparison operator against every value produced by the subquery and returns TRUE if the predicate is satisfied for at least one row. If the subquery returns no rows, ANY yields FALSE.- ALL requires the predicate to be TRUE for every row produced by the subquery. If the subquery returns no rows, ALL yields TRUE.Both operators expect the subquery to return exactly one column, and the data type must be comparable to the outer expression. They can be used with =, <>, !=, >, <, >=, <=. For NOT logical negation, you can wrap the entire predicate in NOT.NULL handling follows three-valued logic: if any comparison result is NULL, the overall evaluation follows SQL's normal NULL rules. For example, expr = ANY(subquery) ignores NULLs in the subquery during equality tests but not during inequality tests, depending on the DBMS.Performance tips: Use EXISTS/NOT EXISTS when only the presence of rows matters. Ensure the subquery has appropriate indexes to avoid scanning large tables.
expression
(scalar) - Value being compared to the subquery resultscomparison_operator
(operator) - One of =, <>, !=, >, =, <=subquery
(SELECT statement) - Must return exactly one column whose data type is comparable to expressionIN, EXISTS, NOT EXISTS, SOME, subqueries, comparison operators, UNION, INTERSECT
SQL-92 standard
ANY (or SOME) succeeds if the predicate is true for at least one subquery value, while ALL requires the predicate to be true for every subquery value.
Yes. SOME is an ISO-standard synonym for ANY and behaves identically in all major databases.
ANY returns FALSE when the subquery returns zero rows. ALL returns TRUE (vacuous truth).
Use ANY/ALL when you need inequality comparisons (<, >, <=, >=) or need to confirm all rows meet a condition. Use EXISTS for pure presence checks and IN for equality checks when NULLs are handled appropriately.