// aggregates reference

SQL EVERY function

The standard SQL aggregate that returns true only if every row in the group is true.

Categoria
Aggregates
Returns
boolean
In this category
15 of 52

Sintaxe

EVERY(boolean) | EVERY(boolean) FILTER (WHERE ...)

Suporte a mecanismos

MotorSupportNotas
SQL Server Not built in No built-in equivalent.
PostgreSQL Sim 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 Sim 23ai+, over the BOOLEAN type

Exemplos

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;

Bom saber

  • 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.

Cheat sheets for the engines that have it: PostgreSQL, Oracle.

// fewer lookups

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.