NULL

Draft

NULL means missing or unknown. That makes it different from an empty string, zero, or false, and it changes how comparisons work.

Find missing values

Use IS NULL because NULL means unknown, not equal to a value.

Loaded Database:null.database-init
SELECT id, title
FROM tickets
WHERE assignee IS NULL;
Loading plan...

Replace NULL for display

COALESCE returns the first non-NULL value from its arguments.

Loaded Database:null.database-init
SELECT title, COALESCE(assignee, 'Unassigned') AS owner
FROM tickets
ORDER BY id;
Loading plan...

NULL is not equal

A comparison with NULL does not return true, so this query finds nothing.

Loaded Database:null.database-init
SELECT id, title
FROM tickets
WHERE assignee = NULL;
Loading plan...

Try Yourself

Loaded Database:null.database-init

The database for this lesson is already loaded. Write any query you want and run it directly in your browser.

Exercises

0 OF 2 DONE
1.Select tickets that have not been closed.
2.Select each title and show missing closed_at values as Still open.

What We Learned

  • NULLrepresents an unknown or missing value.
  • IS NULLchecks whether a value is NULL.
  • COALESCEreturns the first non-NULL value.