Lessons › SQL › Chapter 9: Data Cleaning
SQL lesson
IS NULL and COALESCE() for missing data
First find the empty cells: WHERE discount IS NULL shows which rows are missing a value. Then fill them for your result: COALESCE(discount, 0) shows 0 where it's empty.
Try this lesson free →Example
Find and fill the gaps
SELECT *
FROM customers
WHERE phone IS NULL| customer_id | full_name | phone |
|---|---|---|
| C102 | Bob Tanaka | |
| C104 | David Park |
Step by step
- IS NULL finds the empty cells.
SELECT * FROM customers WHERE phone IS NULL - Fills the empty cells: 0 for numbers, a word like 'Unknown' for text.
SELECT full_name, COALESCE(phone, 'No phone') AS phone FROM customers
Practice
1. Using customers, show the customers with no phone.
SELECT * FROM customers WHERE phone IS NULL2. Using inventory, find the products whose stock_count is missing.
SELECT * FROM inventory WHERE stock_count IS NULLLearn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.
Try this lesson free →