Beginner

286. COALESCE Function

Learn how to return the first non-NULL value from multiple expressions.

📘 Lesson 286 of 728 ⏱ 10 min 🎯 Intermediate

COALESCE evaluates expressions from left to right and returns the first value that is not NULL.

Business databases often contain missing values. COALESCE allows analysts to provide fallback values when preferred data is unavailable.

Display a customer's mobile number when available, otherwise use the alternate phone number.

SQL
SELECT
    CustomerName,
    COALESCE(MobilePhone, AlternatePhone, 'Not Available') AS ContactNumber
FROM Customers;

COALESCE is widely used for missing-value handling, reporting, data transformation, and combining alternative fields.

  • COALESCE returns the first non-NULL value.
  • It can evaluate multiple expressions.
  • It is useful for missing data.
  • It provides fallback values.
  • It is widely supported across SQL databases.
What does COALESCE do?

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

Why is COALESCE useful?

It provides fallback values when preferred database fields contain NULL.

Have you finished this lesson?

Introduction to SQL – All Lessons