The COALESCE function returns the expression of the first non-null value in a list. Its syntax is COALESCE(expression1, expression2, ..., expressionN), and the parameter is the expression to be checked for NULL. Returns an expression whose value is the first non-null value in the list, or NULL if there is no non-null value. It can be used to handle NULL values in different expressions and ensure that a non-null value is returned.
COALESCE function in SQL
What is the COALESCE function?
COALESCE is a SQL function used to handle NULL values. It returns the first non-null expression in a list.
Syntax:
##COALESCE(expression1, expression2, ..., expressionN)
Parameters:
Return value:
The expression of the first non-null value in the list. If there is no non-null value, NULL is returned.Usage example:
Suppose we have a table named "Customers" that contains the "Name" and "Email" columns:<code class="sql">SELECT Name, COALESCE(Email, 'Unknown Email') FROM Customers</code>
Other examples:
: If FirstName is NULL, return LastName; otherwise, return FirstName .
: If Price is NULL, return DefaultPrice; otherwise, return Price.
Note:
The above is the detailed content of What does coalesce in sql mean?. For more information, please follow other related articles on the PHP Chinese website!