The ANY and SOME operators, which are synonyms, perform a Boolean test returning true if even one record in the result set matches the Boolean condition. ANY/SOME is semantically equivalent to IN and EXISTS, but much less widespread. To ensure easy maintenance of your code, use IN or EXISTS rather than ANY/SOME wherever possible.
A bit more explanation, ANY/SOME operators return TRUE when at least one record matches and return FALSE when none match or when there’s an empty result set. If any of the values are NULL, then the operation value will be NULL, not TRUE.
ANY/SOME can be used for filtering checks similar to an IN or EXISTS subquery. In this example, we will get any employee records that also exist in the employees_archive table with a city of Anchorage.
SELECT *
FROM employees
WHERE job_lvl = ANY(SELECT job_lvl FROM employees_archive
WHERE city = ‘Anchorage’)
Syntax
SELECT …
WHERE expression comparison {ANY | SOME} ( subquery )
Explained
WHERE expression
Tests a single value, such as a column, against every value until a match is found for ANY and SOME. One or more rows must match the expression, for ANY and SOME, to return a Boolean TRUE value.
comparison
Compares the expression to the subquery. The comparison must be a standard comparison operator like =, <>, !=, >, >=, <, or <=.
Related Entries
BETWEEN
EXISTS
IN
Operators
SELECT
SOME
WHERE
Speak Your Mind