Comparison equality operator =

Last updated: 2026-11-04

Comparison equality operator =

The equality operator = compares two operands for equality and is the most common filter in SQL. It compares integers, text, dates and even jsonb. Its most easily missed trait is three-valued logic: when either side is NULL the comparison is neither true nor false but NULL (unknown), and WHERE treats such rows as not matching and drops them.

Kindoperator
Example LanguageSQL

📝 Syntax

a = b

Precedence: comparison operators (`< > = <= >= <>`) bind tighter than `IS NULL`/`IS TRUE`, which bind tighter than `NOT`, then `AND`, then `OR`. So `a = b AND c = d` evaluates both comparisons before AND, and `NOT a = b` parses as NOT (a = b). Comparison operators do not chain: `1 < 2 = true` is a syntax error.

⚙️ Parameters

aLeft operand; must be comparable with b.
bRight operand; must be comparable with a.

Returns:The boolean true, false, or NULL when either operand is 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 AS eq_result FROM t_eq ORDER BY id
id | eq_result
---+----------
 1 | true     
 2 | false    
 3 | NULL     
 4 | NULL     
(4 rows)

SELECT id, a IS NOT DISTINCT FROM b AS not_distinct_result FROM t_eq WHERE id IN (3, 4) ORDER BY id
id | not_distinct_result
---+--------------------
 3 | true               
 4 | false              
(2 rows)

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QWhy does WHERE a = NULL match no rows?
ABecause a = NULL evaluates to NULL (unknown) instead of true, and WHERE keeps only true rows. Use `a IS NULL` to match NULLs.
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%

🙏 帮我们做得更好

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

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