Skip to content
SQLSimplified
aggregate

BOOL_AND()

Returns TRUE if every value in the group is TRUE (logical AND across rows).

Description

BOOL_AND is an aggregate function that returns TRUE only if every row in the group satisfies the condition (a logical AND across rows). It's handy for checks like "did every employee in this department pass their review?"

Syntax

BOOL_AND(expression)

Parameters

NameDescriptionOptional
expressionA boolean expression evaluated per row.No

Return Type

Returns a BOOLEAN. If the group is empty it returns NULL (or TRUE in some engines for an empty AND).

Examples

Employees & Departments

Loading database engine...

Employees & Departments

Loading database engine...

Pair with HAVING

Use BOOL_AND in a HAVING clause to keep only groups where every row meets a condition: HAVING BOOL_AND(salary > 40000).

Common Mistakes

  • Confusing with AND in WHERE. BOOL_AND aggregates across rows; a plain AND in WHERE filters a single row.
  • Empty groups. An empty group may return NULL rather than TRUE — handle it if it matters.
  • Non-boolean input. The argument must be boolean; wrap comparisons to make it so.

See also: BOOL_OR, EVERY.

Search

Search lessons, functions, examples, and practice problems