Beginner

189. COALESCE Function

Learn how COALESCE returns the first non-NULL value from a list of expressions.

📘 Lesson 189 of 728 ⏱ 9 min 🎯 Intermediate

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.

SQL
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.

Have you finished this lesson?

Introduction to SQL – All Lessons