Skip to content

COALESCE

  • value1: This parameter is the first expression in the list to be evaluated and returned by the COALESCE function. It can be a column name, a constant, or a function. If the value of this first expression is not NULL, it will be the output of the function.
  • value2, …, valuen: These parameters are the next expressions to be evaluated by the COALESCE function. They can also be column names, constants, or functions. If the first value is NULL, the function will look at the next expressions successively until it finds a non-NULL value. If all expressions are NULL, the COALESCE function will return NULL.
SELECT COALESCE(NULL, 'First Non-NULL value', NULL, 'Second Non-NULL value');
'First Non-NULL value'

The COALESCE function returns the first non-NULL value in the list. In the provided example, ‘First Non-NULL value’ is the first non-NULL value in the list, hence, it is returned.