Coalesce Function

The coalesce() function returns a copy of its first non-NULL argument, or NULL if all arguments are NULL. The function must have at least two (2) arguments.

SELECT coalesce('A', 'B') /* returns A */;

SELECT coalesce('A', NULL) /* returns A */;

SELECT coalesce(NULL, 'B') /* returns B */;

SELECT coalesce(NULL, NULL, 'C') /* returns C */;

SELECT coalesce(NULL, NULL, NULL, NULL) /* returns NULL */;

It is used when value have to be checked in multiple columns e.g. date of purchase, if that is not available i.e. NULL then date of order etc.