Skip to main content

COALESCE

Returns the first non-NULL expression within its arguments; if all arguments are NULL, it returns NULL.

Syntax

COALESCE(<expr1>[, <expr2> ...])

Examples

SELECT COALESCE(1), COALESCE(1, NULL), COALESCE(NULL, 1, 2);

┌────────────────────────────────────────────────────────┐
coalesce(1)coalesce(1, null)coalesce(null, 1, 2)
├─────────────┼───────────────────┼──────────────────────┤
111
└────────────────────────────────────────────────────────┘

SELECT COALESCE('a'), COALESCE('a', NULL), COALESCE(NULL, 'a', 'b');

┌────────────────────────────────────────────────────────────────┐
coalesce('a')coalesce('a', null)coalesce(null, 'a', 'b')
├───────────────┼─────────────────────┼──────────────────────────┤
│ a │ a │ a │
└────────────────────────────────────────────────────────────────┘
Did this page help you?
Yes
No
Explore Databend Cloud for FREE
Low-cost
Fast Analytics
Easy Data Ingestion
Elastic Scaling
Try it today