ANY
ANY
What ANY (and Its Alias SOME) Really Means
x > ANY (subquery) is TRUE if x is greater than at least one row from the subquery — equivalently, greater than the subquery's minimum value. ANY and SOME are exact synonyms in standard SQL. This is a weak, permissive comparison: only one match anywhere in the set is enough.
This is the single most commonly misread operator in this chapter — many people expect ANY to behave like "for any/all of them," implying a strict, universal condition. It's actually the opposite: it's satisfied by clearing just the lowest bar.
Sample data used throughout this chapter:
employees
| id | name | department | salary | manager_id |
|---|---|---|---|---|
| 1 | Alice | Engineering | 95000 | NULL |
| 2 | Bob | Engineering | 72000 | 1 |
| 3 | Carol | Engineering | 68000 | 1 |
| 4 | Dave | Sales | 60000 | 5 |
| 5 | Eve | Sales | 88000 | NULL |
| 6 | Frank | Sales | 55000 | 5 |
| 7 | Grace | Marketing | 70000 | NULL |
| 8 | Heidi | Marketing | 62000 | 7 |
departments
| id | name | budget |
|---|---|---|
| 1 | Engineering | 300000 |
| 2 | Sales | 200000 |
| 3 | Marketing | 150000 |
| 4 | HR | 100000 |
Worked Example
sqlSELECT name, salary FROM employees WHERE salary > ANY (SELECT salary FROM employees WHERE department = 'Marketing');
Marketing salaries are 70000 (Grace) and 62000 (Heidi); the minimum is 62000. salary > ANY (...) is equivalent to salary > 62000.
Checking all 8 employees against 62000:
| name | salary | > 62000? |
|---|---|---|
| Alice | 95000 | yes |
| Bob | 72000 | yes |
| Carol | 68000 | yes |
| Dave | 60000 | no |
| Eve | 88000 | yes |
| Frank | 55000 | no |
| Grace | 70000 | yes |
| Heidi | 62000 | no (not strictly greater) |
Result: Alice, Bob, Carol, Eve, Grace (5 rows).
Translating ANY to Plain English
| Form | Plain-English equivalent |
|---|---|
x = ANY (subq) | same as x IN (subq) |
x > ANY (subq) | x > MIN(subq) |
x < ANY (subq) | x < MAX(subq) |
x >= ANY (subq) | x >= MIN(subq) |
Edge Cases
- If the subquery returns zero rows,
x > ANY (...)is always FALSE — there's nothing to be greater than "at least one of," so the condition can never be satisfied. = ANYis exactly equivalent toIN— a good sanity check if you ever forget which way ANY leans.- Don't confuse
> ANYwith> ALL(17.8) — they compare against opposite ends of the subquery's value range (MIN vs MAX) and can produce very different result sets.
Key Takeaways / Q&A
Q: Is `salary > ANY (subquery)` a strict or permissive condition? A: Permissive/weak — it only needs to beat the smallest value in the subquery's result set.
Q: What is `x > ANY (subquery)` equivalent to? A: x > MIN(subquery) (assuming the subquery returns at least one row).
Q: What if someone reads "ANY" as meaning "must satisfy every row"? A: That's the classic misreading — that behavior is what ALL (17.8) actually provides, not ANY.
Q: What happens with `> ANY` against an empty subquery result? A: Always FALSE — there is no row to be "greater than at least one of."