LOGICAL_AND and LOGICAL_OR are highly useful non-standard SQL functions in BigQuery. These aggregation functions are versatile:
- LOGICAL_OR: Returns
TRUEif at least one value in the grouping bucket isTRUE. - LOGICAL_AND: Returns
TRUEif all values in the grouping bucket areTRUE.
Use cases:
- Pair with
NOTwhen needed. - Compute results for a bucket using
GROUP BYor a window function withOVER (PARTITION BY ...). - Filter output with
HAVINGwhen usingGROUP BY, or withQUALIFYwhen using window functions.
Example: To compute customer data:
- Check if all orders are paid.
- Identify any outstanding orders (not shipped).
- Determine if olives were ordered in the last 3 months.
Alternative:
- Achieve similar results using
MINandMAX:MIN([TRUE,..., FALSE]) = FALSEMAX([TRUE,..., FALSE]) = MAX.










