ALL Operator

Learn how to use the PostgreSQL ALL operator to compare a value against every value in a set returned by a subquery, returning true only when the comparison holds for all values.

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

Quick Answer

The PostgreSQL ALL operator compares a value to every value returned by a subquery. It returns true only if the comparison is true for all values in the set. If the subquery returns no rows, ALL returns true.

Spin up a Postgres database in 20 seconds with Vela.

Try Vela Sandbox

The PostgreSQL ALL operator compares a value to every value in a set returned by a subquery. It returns true only when the comparison is true for every value in the set. If the subquery returns zero rows, ALL always returns true.

ALL operator syntax

expression operator ALL (subquery)
  • operator must be a comparison operator: =, <>, >, >=, <, <=.
  • The subquery must return exactly one column.

The key semantics by operator:

  • value > ALL(subquery) — true if value is greater than the maximum of the set.
  • value < ALL(subquery) — true if value is less than the minimum of the set.
  • value = ALL(subquery) — true if value equals every element (all elements are identical).
  • value <> ALL(subquery) — true if value is not equal to any element (equivalent to NOT IN).

Example: employees who earn more than all managers

Using > ALL finds only employees whose salary exceeds every manager's salary — meaning they beat the highest manager salary:

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

Output:

id | first_name | last_name |  salary
----+------------+-----------+----------
 1 | Bob        | Williams  | 75000.00
(1 row)

Bob's salary of 75,000 exceeds the highest manager salary of 60,000, so he is the only match.

Example: employees who earn less than all managers

Using < ALL finds employees whose salary is below every manager's salary — meaning they earn less than the lowest manager salary (55,000):

SELECT *
FROM employees
WHERE salary < ALL (
  SELECT salary
  FROM managers
)
ORDER BY salary DESC;

Output:

id | first_name | last_name |  salary
----+------------+-----------+----------
 7 | Harry      | Taylor    | 53000.00
 5 | Frank      | Miller    | 52000.00
 3 | David      | Jones     | 50000.00
 6 | Grace      | Wilson    | 49000.00
 4 | Emma       | Brown     | 48000.00
 8 | Ivy        | Moore     | 47000.00
10 | Kate       | Hill      | 44000.00
12 | Mia        | Parker    | 42000.00
(8 rows)

All 8 employees earn less than 55,000, which is the minimum manager salary.

Tips for using ALL correctly

  • <> ALL is equivalent to NOT IN — it returns true if the value does not match any element in the set. This is a useful and readable alternative.
  • Be cautious with NULL in the subquery result. If any value in the set is NULL, <> ALL evaluates to NULL (unknown) rather than true — the same pitfall as NOT IN with nulls.
  • ALL with an empty subquery always returns true. If your subquery might return no rows, consider whether that default behavior is correct for your use case.
  • For simple "greater than maximum" or "less than minimum" checks, using > (SELECT MAX(...)) or < (SELECT MIN(...)) can be more readable and produces equivalent results.

Reference: PostgreSQL documentation — Subquery Expressions (ALL).

Continue in Subquery: EXISTS Operator.

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

Frequently Asked Questions

What does the ALL operator do in PostgreSQL?

ALL compares a value against every value in the set returned by a subquery. The result is true only when the comparison holds for every single value. For example, value > ALL(subquery) returns true only if value is greater than the largest value in the set.

What does value > ALL(subquery) mean in practice?

value > ALL(subquery) is equivalent to checking that value is greater than the maximum of all values in the subquery result. It returns true only when value exceeds every element in the set — meaning it exceeds the highest one.

What does value < ALL(subquery) mean in practice?

value < ALL(subquery) returns true if the value is less than every value in the set — meaning it is less than the smallest one. This is equivalent to value < MIN(subquery result).

What happens when the ALL subquery returns no rows?

When the subquery returns an empty set, ALL evaluates to true for any comparison. This is the opposite of ANY, which returns false for an empty set. The logic is: there are no counterexamples to the comparison, so the condition vacuously holds.

What is the difference between ALL and ANY?

ANY returns true if the comparison holds for at least one value in the set. ALL returns true only if the comparison holds for every value in the set. For an empty subquery result, ANY returns false and ALL returns true. Use ANY for "match any" logic and ALL for "exceeds all" or "matches none" logic.