Beginner

85. COALESCE Function

Learn how to replace NULL values with an alternative value using COALESCE.

📘 Lesson 85 of 728 ⏱ 8 min 🎯 Beginner

COALESCE returns the first non-NULL expression from a list of expressions. It is commonly used to provide a default value when a database column contains NULL.

Missing values can make reports difficult to read. COALESCE allows analysts to replace NULL with a meaningful default such as 'Not Available', zero, or another value.

If an employee does not have a manager assigned, COALESCE can display 'No Manager' instead of NULL.

SQL
SELECT
    EmployeeName,
    COALESCE(ManagerName, 'No Manager') AS Manager
FROM Employees;

COALESCE is useful in reporting, data preparation, customer analysis, financial reporting, and dashboard datasets.

  • COALESCE returns the first non-NULL value.
  • It can replace NULL with a default value.
  • It can accept multiple expressions.
  • It is useful for cleaner reports.
  • It is commonly used in data transformation.
What does COALESCE do?

COALESCE returns the first non-NULL expression from the provided list.

Why is COALESCE useful?

It allows NULL values to be replaced with meaningful default values in queries and reports.

Have you finished this lesson?

Introduction to SQL – All Lessons