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

MySQLMySQLi Database

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)
raja
Published on 20-Feb-2018 13:31:56
Advertisements