Logical disjunction operator OR
Last updated: 2026-11-04
Logical disjunction operator OR
OR joins two boolean conditions and yields true when either side is true. It also follows three-valued logic: true OR NULL is true (already decided), while false OR NULL is NULL (cannot be decided). WHERE still keeps only rows whose result is true.
| Kind | operator |
|---|---|
| Example Language | SQL |
📝 Syntax
a OR b
Precedence: `OR` is the lowest-precedence logical operator, sitting just above parentheses. `a = 1 OR b = 2 AND c = 3` parses as `a = 1 OR (b = 2 AND c = 3)` because AND binds tighter. Use parentheses to make grouping explicit in complex conditions. Like AND, OR is commutative, but the left operand is not guaranteed to be evaluated first.
⚙️ Parameters
| a | Left boolean condition; participates under three-valued logic when NULL. |
|---|---|
| b | Right boolean condition; participates under three-valued logic when NULL. |
Returns:The boolean true, false, or NULL when both operands are NULL or combine false with NULL.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
SELECT id, a, b, a OR b AS or_result FROM t_or ORDER BY id
id | a | b | or_result
---+-------+-------+----------
1 | true | true | true
2 | true | false | true
3 | false | NULL | NULL
4 | true | NULL | true
5 | NULL | NULL | NULL
(5 rows)
SELECT a OR b IS NULL AS result_is_null FROM t_or WHERE id = 3
result_is_null
--------------
true
(1 row)
📌 Key Points
- Three-valued logic: true OR NULL is true, false OR NULL is NULL, NULL OR NULL is NULL.
- WHERE keeps only rows whose result is true, so NULL rows are filtered out.
- OR binds looser than AND — always parenthesise mixed conditions.
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QIs FALSE OR NULL false?
ANo, it is NULL. "False or unknown" can be neither confirmed true nor confirmed false, so the result is unknown.