Skip to content
C

ALL


ALL

What ALL Really Means

x > ALL (subquery) is TRUE only if x is greater than every single row the subquery returns — equivalently, greater than the subquery's maximum value. This is a strict, demanding comparison: x has to clear the highest bar in the set, not just any bar.

This is the direct contrast to ANY (17.7): ANY is satisfied by beating the weakest competitor; ALL requires beating the strongest one.

Sample data used throughout this chapter:

employees

idnamedepartmentsalarymanager_id
1AliceEngineering95000NULL
2BobEngineering720001
3CarolEngineering680001
4DaveSales600005
5EveSales88000NULL
6FrankSales550005
7GraceMarketing70000NULL
8HeidiMarketing620007

departments

idnamebudget
1Engineering300000
2Sales200000
3Marketing150000
4HR100000

Worked Example

sql
SELECT name, salary FROM employees WHERE salary > ALL (SELECT salary FROM employees WHERE department = 'Marketing');

Marketing salaries are 70000 (Grace) and 62000 (Heidi); the maximum is 70000. salary > ALL (...) is equivalent to salary > 70000.

Checking all 8 employees against 70000:

namesalary> 70000?
Alice95000yes
Bob72000yes
Carol68000no
Dave60000no
Eve88000yes
Frank55000no
Grace70000no (not strictly greater than itself)
Heidi62000no

Result, ordered by salary descending: Alice (95000), Eve (88000), Bob (72000) — 3 rows.

ANY vs ALL, Side by Side

Same subquery (Marketing salaries), same outer comparison direction, wildly different result sizes:

  • salary > ANY (...) → 5 rows (beats the weakest Marketing salary, 62000)
  • salary > ALL (...) → 3 rows (beats the strongest Marketing salary, 70000)

This is exactly why mixing them up is a real bug, not just a style choice — swapping ANY for ALL (or vice versa) silently changes which rows qualify, with no error to warn you.

Translating ALL to Plain English

FormPlain-English equivalent
x = ALL (subq)true only if the subquery returns one row (or zero) equal to x — rarely useful with =
x > ALL (subq)x > MAX(subq)
x < ALL (subq)x < MIN(subq)
x <> ALL (subq)same as x NOT IN (subq)

Edge Cases

  • If the subquery returns zero rows, x > ALL (...) is always TRUE — vacuously true, since there's no row that fails to satisfy the condition ("greater than every one of zero rows" is trivially satisfied). This is the mirror opposite of > ANY's behavior on an empty set (always FALSE) — an easy point to mix up.
  • <> ALL is equivalent to NOT IN, and inherits the exact same NULL danger discussed in 17.6 — a NULL in the subquery can make the whole thing UNKNOWN.

Key Takeaways / Q&A

Q: Is `salary > ALL (subquery)` a strict or permissive condition? A: Strict — it must beat every row, i.e., the maximum.

Q: What does `> ALL` reduce to? A: > MAX(subquery).

Q: What happens when the ALL subquery is empty? A: The condition becomes vacuously TRUE — the opposite of ANY's FALSE-on-empty behavior.

Q: Someone says "ANY means it just has to match anything, so it should be the stricter one." Correct this. A: Backwards — ANY is the weak/permissive one (beats the minimum); ALL is the strict one (beats the maximum).

Mock Test

  • ALL - Quick Test

    8 questions on ALL.

    8 questions · 8 min · Medium
    Start Mock Test