Home >Database >Mysql Tutorial >Which MySQL function is used to find the first non-NULL value from a list of values?

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

PHPz
PHPzforward
2023-09-03 22:01:02881browse

哪个 MySQL 函数用于从值列表中查找第一个非 NULL 值?

We can use the MySQL COALESCE() function to get the first non-NULL value from the list of values ​​as output. In other words, the function will check all values ​​until it finds a non-null value. It can take one or more parameters. It has the following syntax:

COALESCE(value1, value2, …, valueN)

Example

Here 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)

The above is the detailed content of Which MySQL function is used to find the first non-NULL value from a list of values?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete