SQL

IS NULL and IS NOT NULL

Handling NULL Values

NULL represents missing or unknown data. It's not the same as 0, empty string, or "nothing" — it means the value is unknown.

⚠️ The #1 Mistake with NULL

You cannot use = to check for NULL!

-- ❌ WRONG - This will NEVER find NULL values!
SELECT * FROM customers WHERE email = NULL;

-- ✅ CORRECT SELECT * FROM customers WHERE email IS NULL;

-- ✅ Find rows where email exists SELECT * FROM customers WHERE email IS NOT NULL;

Why Can't You Use = NULL?

In SQL, NULL means "unknown". Comparing anything to an unknown value is also unknown — so NULL = NULL returns FALSE, not TRUE!

Real-World Examples of NULL

  • Customer without a phone number
  • Order without a shipping date (not yet shipped)
  • Product without a description

Your Task

Find all customers who have not provided an email address.

query.sql
Loading SQL engine...
Downloading SQL engine… (one-time)

Downloading SQL engine… (one-time)

This runs entirely in your browser and is cached for next time.