capypad
0 day streak
sql / expert
Snippet

Universal Quantification with the ALL Predicate

The ALL predicate compares a scalar value against every value in a subquery's result set. It returns true only if the comparison holds for every row, providing a concise way to implement universal quantification logic.

snippet.sql
sql
1
2
3
4
5
6
SELECT project_id
FROM projects
WHERE budget > ALL (
SELECT avg_cost
FROM regional_benchmarks
);
Breakdown
1
WHERE budget > ALL (...)
The predicate ensures the budget is strictly greater than every single value returned by the subquery.
2
SELECT avg_cost FROM regional_benchmarks
A subquery generating the set of values for the universal comparison.