ANY Operator

Learn how to use the PostgreSQL ANY operator to compare a value against a set of values returned by a subquery, returning true if any single comparison succeeds.

5 min read · Last updated: March 2026 · Back to overview

Quick Answer

The PostgreSQL ANY operator compares a value to a set of values from a subquery using a comparison operator. It returns true if the comparison is true for at least one value in the set. SOME is a synonym for ANY.

Spin up a Postgres database in 20 seconds with Vela.

Try Vela Sandbox

The PostgreSQL ANY operator compares a value to a set of values returned by a subquery using a comparison operator. It returns true if the comparison holds for at least one value in the set. SOME is an alias for ANY and behaves identically.

ANY operator syntax

expression operator ANY (subquery)
  • expression — the value to compare (typically a column).
  • operator — any comparison operator: =, <>, >, >=, <, <=.
  • subquery — must return exactly one column. If it returns zero rows, ANY is always false.

Example: using ANY with the = operator

This query finds employees whose salary matches any manager's salary:

SELECT *
FROM employees
WHERE salary = ANY (
  SELECT salary
  FROM managers
);

Output:

id | first_name | last_name |  salary
----+------------+-----------+----------
 2 | Charlie    | Davis     | 55000.00
(1 row)

Charlie's salary of 55,000 matches one of the manager salaries (55K, 58K, 60K), so he is returned. value = ANY (subquery) is equivalent to value IN (subquery).

Example: using ANY with the > operator

This query finds employees who earn more than at least one manager's salary:

SELECT *
FROM employees
WHERE salary > ANY (
  SELECT salary
  FROM managers
);

Output:

id | first_name | last_name |  salary
----+------------+-----------+----------
 9 | Jack       | Anderson  | 56000.00
11 | Liam       | Clark     | 59000.00
(2 rows)

Jack (56K) is greater than the lowest manager salary (55K), so he qualifies. Liam (59K) is greater than both 55K and 58K.

Example: using ANY with the < operator

This query finds employees who earn less than at least one manager — in practice, almost everyone qualifies:

SELECT *
FROM employees
WHERE salary < ANY (
  SELECT salary
  FROM managers
);

Output includes 11 of 12 employees, because any salary below the highest manager salary (60K) satisfies the condition for at least one manager value.

Tips for using ANY effectively

  • = ANY is interchangeable with IN for subqueries. Use whichever reads more clearly for your team.
  • <> ANY is NOT the same as NOT IN. <> ANY returns true if the value differs from at least one element in the set (which is almost always true). Use NOT IN or <> ALL to exclude rows that match any value.
  • If the subquery can return NULL values and you use = ANY, rows with a null in the set do not cause the comparison to fail — but they will not match either. Be aware of nullability in the subquery column.
  • For a fixed list of values, ANY(ARRAY[val1, val2, val3]) is a clean alternative to a subquery.

Reference: PostgreSQL documentation — Subquery Expressions (ANY/SOME).

Continue in Subquery: ALL Operator.

Related in this section: Subquery · Correlated Subquery · ALL Operator

Frequently Asked Questions

What does the ANY operator do in PostgreSQL?

ANY compares a scalar value against every value returned by a subquery using a specified comparison operator. If the comparison is true for at least one value in the set, ANY returns true. If the subquery returns zero rows, ANY always returns false.

What is the difference between ANY and IN?

value = ANY (subquery) is equivalent to value IN (subquery) — both return true if the value matches at least one element in the set. However, ANY is more flexible because it works with any comparison operator, not just equality. For example, salary > ANY (subquery) has no direct IN equivalent.

What happens when the ANY subquery returns an empty set?

If the subquery returns no rows, ANY always evaluates to false regardless of the comparison operator or the left-hand value. This is different from ALL, which evaluates to true when the subquery is empty.

Can I use ANY with arrays instead of a subquery?

Yes. PostgreSQL allows ANY with array literals or array expressions: WHERE salary = ANY(ARRAY[55000, 58000, 60000]). This is useful when you have a fixed list of values or an array stored in a variable, and avoids writing a subquery.

Is SOME the same as ANY in PostgreSQL?

Yes, SOME is a synonym for ANY in PostgreSQL and can be used interchangeably. Both keywords are part of the SQL standard. ANY is more commonly used in practice.