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