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.
| Kind | operator |
|---|---|
| Example Language | SQL |
📝 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
| a | Left operand; must be comparable with b. |
|---|---|
| b | Right 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
- NULL propagation: when either operand is NULL the result is NULL and WHERE drops the row.
- `NULL <> NULL` is NULL; use `IS DISTINCT FROM` to decide whether two NULLs are different.
- `IS DISTINCT FROM` treats NULL as a comparable value: two NULLs are not distinct, NULL versus a non-NULL is distinct.
💡 Related Cases
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).