Logical conjunction operator AND
Last updated: 2026-11-04
Logical conjunction operator AND
AND joins two boolean conditions and yields true only when both sides are true. It follows SQL three-valued logic: true AND false is false, false AND NULL is also false, but true AND NULL is NULL because it cannot be decided either way. WHERE keeps only rows whose result is true, so NULL rows are filtered out.
| Kind | operator |
|---|---|
| Example Language | SQL |
📝 Syntax
a AND b
Precedence: `AND` binds tighter than `OR`, looser than `NOT`, and looser than the comparison operators. `a = 1 AND b = 2 OR c = 3` parses as `(a = 1 AND b = 2) OR c = 3`, so parenthesise `a = 1 AND (b = 2 OR c = 3)` when you want OR to cover the whole group. AND stays commutative under three-valued logic: false AND NULL and NULL AND false are both false, while true AND NULL and NULL AND true are both NULL.
⚙️ 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 the operands are NULL and the outcome cannot be decided.
▶ 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 AND b AS and_result FROM t_and ORDER BY id
id | a | b | and_result
---+-------+-------+-----------
1 | true | true | true
2 | true | false | false
3 | false | NULL | false
4 | true | NULL | NULL
5 | NULL | NULL | NULL
(5 rows)
SELECT a AND b IS NULL AS result_is_null FROM t_and WHERE id = 4
result_is_null
--------------
true
(1 row)
📌 Key Points
- Three-valued logic: true AND NULL is NULL, false AND NULL is false, NULL AND NULL is NULL.
- WHERE keeps only rows whose result is true, so rows whose result is NULL are filtered out.
- The PostgreSQL docs are explicit: AND and OR are commutative (swapping the operands does not change the result), but the left operand is not guaranteed to be evaluated first, and this is not the left-to-right short-circuiting of some programming languages — do not rely on side effects inside AND.
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QWhat does TRUE AND NULL return?
AIt returns NULL, not false. NULL means unknown, and "true and unknown" cannot be decided, so the result stays unknown.