📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

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 │ └────────────────────────────────────────────────────────────────┘

Was this page helpful?