Lesson 16 of 30
53%
NULL Values
NULL means unknown. It is not zero. It is not an empty string.
Think of a blank locker. You did not store a fact yet.
Insert a missing value
sql
Result
Query OK, 1 row affected
Find NULL
WHERE city = NULL does not work.
Use IS NULL and IS NOT NULL.
sql
Result
| name |
|---|
| Kai |
1 row
| name |
|---|
| Ada |
| Sam |
| Lin |
| Omar |
| Nia |
5 rows
IFNULL
IFNULL swaps NULL for a stand-in in the result.
sql
Result
| name | age_or_zero |
|---|---|
| Ada | 12 |
| Sam | 11 |
| Lin | 13 |
| Omar | 12 |
| Nia | 10 |
| Kai | 0 |
6 rows
NULL in math
NULL plus 1 is still NULL. Unknown plus one is still unknown.
That is why COUNT(age) skips NULL ages, while COUNT(*) counts rows.
Tip: Decide which columns may be NULL. Required facts should be NOT NULL.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.