// aggregates reference

SQL BOOL_OR function

Returns true when at least one input row that is not NULL evaluates to true.

類別
Aggregates
Returns
boolean
In this category
14 of 52

語法

BOOL_OR(boolean) | BOOL_OR(boolean) FILTER (WHERE ...)

引擎支援

引擎Support備註
SQL Server Not built in No built-in equivalent.
PostgreSQL 是 Supported under this name.
MySQL Not built in use MAX(col = 1)
SQLite Not built in use MAX(col) over 0/1 values
Oracle Different name or syntax 23ai+ spells it BOOLEAN_OR_AGG; older releases use MAX over a 0/1 CASE

範例

PostgreSQL

SELECT bool_or(has_exception) FROM runs WHERE day = '2026-11-19';

MySQL

SELECT project_id, MAX(blocked = 1) AS any_blocked FROM tasks GROUP BY project_id;

小知識

  • NULL inputs are skipped; a group of all NULLs returns NULL, not false. Use COALESCE(BOOL_OR(x), false) for a two-valued result.
  • Without BOOL_OR, MAX over 0/1 values does the job: MAX(col = 1) in MySQL or MAX(CASE WHEN cond THEN 1 ELSE 0 END) everywhere. Oracle 23ai ships it as BOOLEAN_OR_AGG.
  • bool_or(x) is exactly NOT bool_and(NOT x) for non-NULL inputs, which matters when porting between engines that only have one of them.

Questions about BOOL_OR

What does BOOL_OR return for an empty group?

NULL, not false. COALESCE(BOOL_OR(x), false) if you need a strict boolean.

What is the MySQL equivalent of BOOL_OR?

MAX(flag = 1): MySQL compares yield 1 or 0, and MAX picks out the 1 if any row has it.

How does BOOL_OR treat NULL rows?

They are ignored. A NULL row never makes the result true or false; only non-NULL rows decide.

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.