SQL.Why do column = NULL and column <> NULL not work as expected, and when should you use IS NULL and IS NOT NULL?

`NULL` represents a missing or unknown value. Comparing anything to it using `=` or `<>` produces **UNKNOWN**, even `NULL = NULL`.

Since `WHERE` keeps only **TRUE** conditions, neither comparison selects rows.

Use these predicates instead:

```sql
WHERE column IS NULL      -- Select missing values
WHERE column IS NOT NULL  -- Select present values
```

**Interview answer:** “Use IS NULL and IS NOT NULL to check whether a value is missing. Ordinary comparisons with NULL return UNKNOWN, which WHERE filters out.”
This entry was posted in Без рубрики. Bookmark the permalink.