Comparison inequality operator <>

Last updated: 2026-11-04

Comparison inequality operator <>

The inequality operator <> reports whether two operands differ; PostgreSQL also accepts != as a synonym. Like =, it follows three-valued logic: the result is NULL when either operand is NULL. It differs from IS DISTINCT FROM, which treats NULL as an ordinary comparable value and therefore yields a definite true or false.

Kindoperator
Example LanguageSQL

📝 Syntax

a <> b        -- a != b is accepted too

Precedence: it sits at the same level as the other comparison operators (`< > = <= >= <>`), above `IS NULL`, above `NOT`, above `AND` and above `OR`. Comparison operators do not chain, so `a <> b <> c` is invalid.

⚙️ 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 neq_result FROM t_neq ORDER BY id
id | neq_result
---+-----------
 1 | true      
 2 | false     
 3 | NULL      
(3 rows)

SELECT id, a IS DISTINCT FROM b AS distinct_result FROM t_neq WHERE id = 3
id | distinct_result
---+----------------
 3 | false          
(1 row)

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QIs NULL <> NULL true?
ANo, it is NULL. SQL uses three-valued logic and NULL means unknown, so even the inequality of two unknowns is unknown. Use `IS DISTINCT FROM` to decide it (it returns false for two 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%

🙏 帮我们做得更好

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

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