COALESCE evaluates its arguments from left to right and returns the first value that is not NULL.
COALESCE provides a convenient way to replace missing values with fallback values.
If an employee has no recorded bonus, COALESCE can display 0 instead.
SELECT
EmployeeName,
COALESCE(Bonus, 0) AS Bonus
FROM Employees;
COALESCE is widely used in reporting, data cleaning, financial calculations, customer analysis, and combining fallback values.
- COALESCE returns the first non-NULL value.
- It can accept multiple expressions.
- It is useful for handling missing values.
- It can provide fallback values.
- It is commonly used in reports and calculations.
What does COALESCE do?
COALESCE returns the first non-NULL expression from the values provided.
How can COALESCE replace NULL with zero?
Use COALESCE(column_name, 0), which returns the column value when available and 0 when it is NULL.