COALESCE returns the first non-NULL expression from the list of expressions provided to it.
COALESCE is extremely useful for handling missing values and creating cleaner reports.
Display an employee's manager name and show 'Not Assigned' when the manager is missing.
SELECT
EmployeeName,
COALESCE(ManagerName, 'Not Assigned') AS ManagerName
FROM Employees;
Analysts use COALESCE for data cleaning, reporting, calculations, default values, and combining information from multiple sources.
- COALESCE returns the first non-NULL value.
- It can accept multiple expressions.
- It is useful for NULL handling.
- It can provide default values.
- It is widely supported by relational databases.
What does COALESCE do?
COALESCE returns the first non-NULL expression from the supplied list.
Can COALESCE accept more than two values?
Yes. COALESCE can evaluate multiple expressions and return the first non-NULL value.