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.

Kindoperator
Example LanguageSQL

📝 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

aLeft boolean condition; participates under three-valued logic when NULL.
bRight 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

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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏