SQL • LESSON 30
NULL Handling with COALESCE
Learn how to replace NULL values with useful fallback values.
🔴 Advanced⏱ 3 Minutes⭐ 470 XP
🤔 THE QUESTION
What should we display when an employee's department value is NULL?
💡 WHAT IS IT?
COALESCE returns the first non-NULL value from the values provided to it.
🎯 WHAT IS IT USED FOR?
It is useful for replacing missing values with defaults, making reports easier to read, and preventing NULL values from producing confusing output.
💻 EXAMPLE
SELECT
name,
COALESCE(department, 'Not Assigned')
AS department
FROM employees;Mission Brief
Practice using COALESCE to replace missing department values with a readable fallback.
Objectives
- ✓ SELECT
- ✓ COALESCE
- ✓ NULL
- ✓ Fallback values
- ✓ Column aliases