SQL: COALESCE reference
19 March 2023 (Updated 19 March 2023)
On this page
In a nutshell
The COALESCE
function is used to return the first non-null value from a list of expressions.
Syntax
COALESCE(expression1, expression2, ..., expressionN)
Example
SELECT COALESCE(column1, column2, 'default') as result
FROM my_table;
Here, COALESCE
will return the first non-null value from column1
or column2
. If both are null, then 'default'
is returned.
Tagged:
MySQL
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment