SQL ALL operator
True when the comparison holds for every element of the list or subquery.
- 카테고리
- 조건부
- Returns
boolean- In this category
- 15 of 43
구문
x > ALL (subquery) | x <> ALL (subquery)
엔진 지원
| 엔진 | Support | 메모 |
|---|---|---|
| SQL Server | Different name or syntax | subqueries only |
| PostgreSQL | 예 | subqueries and arrays |
| MySQL | Different name or syntax | subqueries only |
| SQLite | Not built in | no ALL; use NOT EXISTS or a MAX/MIN subquery |
| Oracle | 예 | subqueries and literal lists |
예시
PostgreSQL
SELECT * FROM products WHERE price > ALL (SELECT price FROM products WHERE category = 'budget');
Oracle
SELECT * FROM products WHERE price > ALL (SELECT price FROM products WHERE category = 'budget');
알아 두면 좋은 정보
- x > ALL (subquery) equals x > (SELECT MAX(...)) only when the subquery returns at least one row and no NULLs. On an empty subquery ALL is TRUE while the MAX comparison is UNKNOWN.
- x <> ALL (list) is the same as NOT IN: one NULL in the subquery empties your result set.
- An empty subquery makes ALL vacuously true (and ANY false), so a broken subquery can silently pass every row.
Questions about ALL
ALL vs MAX?
x > ALL (SELECT y FROM t) matches x > (SELECT MAX(y) FROM t) when t has rows and y has no NULLs. On an empty t the ALL form keeps every row and the MAX form keeps none.
What does ALL return for an empty subquery?
TRUE. Vacuously, every (zero) comparison passed. ANY returns FALSE for the same input.
Why did <> ALL return nothing?
A NULL in the subquery: NOT IN's trap. Filter the NULLs or use NOT EXISTS.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.