SQLite 3 reference · Conditional and Type Functions

SQLite COALESCE() Function

Return the first argument that isn't NULL. The standard way to replace NULL with a default value.

SQLite 3

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

coalesce(X, Y, ...)

Parameters

ParameterDescription
X, Y, ... Two or more values, checked in order.

Return value

The first non-NULL value, or NULL.

Examples

A default for missing valuesTry it yourself
SELECT name, coalesce(email, 'no email') AS email
FROM customers
WHERE customer_id IN (4, 5);

Output

name | email
Linus Torvalds | [email protected]
Margaret Hamilton | no email
Several fallbacksTry it yourself
SELECT name, coalesce(city, country, '?') AS place
FROM customers
WHERE customer_id IN (6, 7);

Output

name | place
Tim Berners-Lee | Geneva
Barbara Liskov | USA

In other languages

Was this page helpful?