Master programming syntax, solve interactive challenges & run live code in Syntaxis Explore Arena →
Reference / SQL

COALESCE()

Evaluates the arguments in order and returns the current value of the first expression that initially does not evaluate to NULL.

Syntax
COALESCE(val1, val2, ..., valN)

Parameters

NameTypeDescription
val1...valNanyExpressions of compatible datatypes to test.

Examples

Fallback phone or email
SELECT user_id, COALESCE(phone_number, backup_email, 'No contact info') AS primary_contact
FROM user_contacts;
Short-circuits: arguments after the first non-null value are not evaluated.