SQL – NULL Values
Understand what NULL means in SQL, why it is different from zero or empty string, and how to work with it.
Table of Contents
NULL is one of SQL’s most misunderstood concepts. It does not mean zero. It does not mean an empty string. It means the absence of any value — the data simply does not exist for that field. A student who hasn’t received a grade yet has a NULL grade, not a grade of zero or an empty string.
NULL is infectious: any arithmetic or comparison with NULL returns NULL. 5 + NULL = NULL. 100 > NULL = NULL (not true, not false — unknown). This is called three-valued logic and it affects how you write WHERE conditions. You cannot use = NULL; you must use IS NULL or IS NOT NULL.
NULL rules
| Expression | Result |
|---|---|
| NULL = NULL | NULL (not TRUE!) |
| NULL IS NULL | TRUE |
| 5 + NULL | NULL |
| COALESCE(NULL, 0) | 0 |
Try It Yourself — Interactive SQL Editor
Edit the query below and click Run Query ▶ to see live results powered by SQLite running directly in your browser.
Key Points
- NULL ≠ zero, NULL ≠ empty string — it means “no value”
- Use IS NULL / IS NOT NULL, never = NULL
- COALESCE(col, default) replaces NULL with a fallback value
- COUNT(*) counts all rows; COUNT(col) ignores NULLs
Pro Tip from CodesCompiler: The best way to learn SQL is to break things intentionally — modify the query above, change the WHERE conditions, try different columns. Every error teaches you something the docs cannot.
In the next lesson, we continue exploring SQL’s powerful feature set to build your database mastery.