Summary - NULL handling
- SQL course
- Beginner
- Lesson 64/115
- 5 min
Write NULL-safe queries with COALESCE and NULLIF.
Summary - NULL handling
In this group you learned NULL, IS NULL, COALESCE, NULLIF and IFNULL. Handling NULL correctly is key to robust queries.
SELECT COALESCE(NULLIF(total, 0), 1) AS duzelti FROM orders;If total is 0 returns NULL then 1.
COALESCE(NULLIF(total, 0), 1) AS duzelti is selected from orders.
Practice Summary - NULL handling
Select names from customers where email is null.
Starter code
-- summary null
SELECT name
FROM customers
WHERESample solution
SELECT name
FROM customers
WHERE email IS NULLExpected output
name Mehmet Zeynep
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which gives the first non-NULL value?
- NULLIF
- IFNULL
- COALESCE Correct answer
- IS NULL
Explanation: COALESCE returns the first non-NULL value.
2 Summary - NULL handling: match the terms
| Term | Meaning |
|---|---|
IS NULL |
empty |
COALESCE |
fallback |
NULLIF |
null if equal |
IFNULL |
two fallbacks |