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
Release: 2023-09-03 22:01:02
forward
908 people have browsed it

哪个 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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template