THE WORLD'S LARGEST WEB DEVELOPER SITE

MySQL COALESCE() Function

❮ MySQL Functions

Example

Return the first non-null expression in a list:

SELECT COALESCE(NULL, NULL, NULL, 'W3Schools.com', NULL, 'Example.com');
Try it Yourself »

Definition and Usage

The COALESCE() function returns the first non-null expression in a list.

Syntax

COALESCE(expr1, expr2, ...., expr_n)

Parameter Values

Parameter Description
expr1, expr2, expr_n Required. The expressions to test

Technical Details

Works in: MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

More Examples

Example

Return the first non-null expression in a list:

SELECT COALESCE(NULL, 1, 2, 'W3Schools.com');
Try it Yourself »

❮ MySQL Functions