Skip
Arish's avatar

146. COALESCE Function


COALESCE Function

Returns first non-NULL value.

sql
1SELECT COALESCE(phone, email, 'No Contact') AS contact
2FROM students;

Checks phone first, then email, then default.

With Multiple Columns

sql
1SELECT name,
2  COALESCE(nickname, name) AS display_name
3FROM students;