SQL EVERY function
The standard SQL aggregate that returns true only if every row in the group is true.
- Returns
boolean- In this category
- 15 of 52
语法
EVERY(boolean) | EVERY(boolean) FILTER (WHERE ...)
引擎支持
| 引擎 | Support | 备注 |
|---|---|---|
| SQL Server | Not built in | No built-in equivalent. |
| PostgreSQL | 是 | synonym of bool_and |
| MySQL | Not built in | no EVERY(); use MIN(status = 'paid') or SUM(status = 'paid') = COUNT(status) |
| SQLite | Not built in | No built-in equivalent. |
| Oracle | 是 | 23ai+, over the BOOLEAN type |
示例
PostgreSQL
SELECT category_id, every(price > 0) AS prices_ok FROM products GROUP BY category_id;
MySQL
SELECT category_id, SUM(price > 0) = COUNT(price) AS prices_ok FROM products GROUP BY category_id;
值得了解
- NULLs are skipped: EVERY ignores NULL rows entirely and only true non-NULL rows keep the result true.
- Empty and all-NULL groups return NULL, not false.
- The SQL standard also defines ANY and SOME aggregates, but PostgreSQL rejects them as aggregate names because x = ANY(...) already means something else.
Questions about EVERY
Is EVERY the same as BOOL_AND?
Yes, in PostgreSQL they are synonyms. EVERY is the SQL standard name; Oracle 23ai has EVERY and BOOLEAN_AND_AGG.
Does EVERY count NULL rows?
No. NULLs are skipped, so a group of one true row and five NULLs is still true.
What replaces EVERY in MySQL?
MIN(condition), or SUM(condition) = COUNT(col): both return 1 only when every non-NULL row satisfies the condition. COUNT(*) would count NULL rows and break the match.
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: PostgreSQL, 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.