Which MySQL function is used to find first non-NULL value from a list of values?


We can use MySQL COALESCE() function to get the first non-NULL value as output from a list of values. In other words, this function will check all the values until non-null value found. It can take one or more than one argument. It is having the following syntax:

COALESCE(value1, value2, …, valueN)

Example

Following is an example to demonstrate it −

mysql> Select COALESCE(NULL, NULL, NULL, 'Ram', 'Aarav', NULL);
+--------------------------------------------------+
| COALESCE(NULL, NULL, NULL, 'Ram', 'Aarav', NULL) |
+--------------------------------------------------+
| Ram                                              |
+--------------------------------------------------+
1 row in set (0.00 sec)

Updated on: 20-Jun-2020

138 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements