# IS NULL vs = NULL in SQL

Source: https://sqlstreak.com/sql/is-null-vs-equals-null · Tested on PostgreSQL 18.6 and SQLite 3.54.1; results generated 2026-11-22.


**Short answer:** `= NULL` never matches, because comparing anything with NULL gives NULL (unknown), and WHERE only keeps rows where the condition is true. Test for missing values with `IS NULL` and `IS NOT NULL`.

## Side by side

| | IS NULL | = NULL |
| --- | --- | --- |
| Result for a NULL value | true | NULL (unknown) |
| Rows WHERE keeps | The rows with NULL | None |
| Error? | No | No: it fails silently |
| Comparing two columns null-safely | IS NOT DISTINCT FROM | Treats two NULLs as unknown |

## Examples

### = NULL: no rows, no error

```sql
SELECT name, species
FROM pets
WHERE breed = NULL;
```

PostgreSQL:

| name | species |
| --- | --- |

SQLite:

|  |
|  |

### IS NULL: the pets with no recorded breed

```sql
SELECT name, species
FROM pets
WHERE breed IS NULL
ORDER BY name;
```

Result (both engines):

| name | species |
| --- | --- |
| Bean | dog |
| Clover | rabbit |
| Luna | cat |
| Pickles | dog |
| Pumpkin | cat |
| Tofu | cat |

### Why: what the comparisons return

PostgreSQL shows true/false; SQLite shows 1 and 0. Either way `= NULL` gives NULL.

```sql
SELECT NULL = NULL AS equals_null,
       NULL IS NULL AS is_null,
       NULL IS NOT DISTINCT FROM NULL AS null_safe_equal;
```

PostgreSQL:

| equals_null | is_null | null_safe_equal |
| --- | --- | --- |
| NULL | true | true |

SQLite:

| equals_null | is_null | null_safe_equal |
| --- | --- | --- |
| NULL | 1 | 1 |

## When to use which

- **IS NULL:** Always, to find missing values: `WHERE breed IS NULL`, `WHERE phone IS NOT NULL`.
- **= NULL:** Never in a WHERE clause. To compare two columns that may both be NULL, use `IS NOT DISTINCT FROM`.

## Common mistakes

- `WHERE x = NULL` or `WHERE x <> NULL`: both return nothing.
- `WHERE x != 'cat'` doesn't return rows where x is NULL either: add `OR x IS NULL` if you want them.
- Treating an empty string as NULL: `''` is a value. Convert with `NULLIF(x, '')` first.
