MySQL COALESCE() Function Examples
Let’s look at some examples of the COALESCE() function in MySQL and understand how to use COALESCE function.
Using COALESCE() function on a list example
In this example, we will use the COALESCE function on a list of values where the first value is NULL.
Query:
SELECT COALESCE(NULL, 'A', 'B', NULL);
Output:
A
Example 2
In this example, we will use the COALESCE function on a list of values where the first value is not NULL
Query
SELECT COALESCE('A', NULL, 'B', NULL);
Output:
A
MySQL COALESCE() Function
The MySQL COALESCE() function returns the first non-null value in a list of expressions.
Contact Us