The COALESCE SQL Function in MySQL and MariaDB - Non-NULL value from list |
|
| COALESCE | Syntax: | COALESCE(%, %) | Return value: | Depending on the data types used | Function type: | Comparison function, NULL function | |
| | The COALESCE() function returns the first value from a list that is not NULL.
If no non-NULL value is found, COALESCE() returns NULL. | SQL Examples for the COALESCE function |
|
select COALESCE(null, 'Test', null, 'Test2');
select COALESCE(null, 45, null, 13);
select COALESCE(null, null, null, null);
|
|
COALESCE(null, 'Test', null, 'Test2') |
varchar(5) BINARY |
Test |
|
|
COALESCE(null, 45, null, 13) |
int(2) |
45 |
|
|
COALESCE(null, null, null, null) |
|
NULL |
|
|
| The examples were created with the MyWAY SQL manager: | How to use the COALESCE() function in MySQL and MariaDB databases | The MySQL and MariaDB COALESCE() function returns the first non-NULL expression from a list of expressions, where function evaluates the expressions in order from left to right and returns the first non-NULL value. If all expressions are NULL, the function returns NULL. The function can also be used with more than two expressions, if you want to process null values and provide default values or alternative expressions. The function allows replacing NULL values with alternative or desired values in results of SQL queries or expressions. The COALESCE() function in MySQL and MariaDB provides a convenient way to handle NULL values. | | Further MySQL und MariaDB SQL Comparison functions | |
| | More information about the COALESCE SQL function: and and |
|
|
|
|