IFNULL
Purpose
Returns the first argument if it is not NULL, otherwise it returns the second argument.
Syntax
ifnull::=
Usage notes
If expr1 is NULL, expr2 is returned, otherwise expr1 is returned.
The IFNULL(expr1,expr2) function is equivalent to the CASE expression CASE WHEN expr1 IS NOT NULL THEN expr1 ELSE expr2 END.
IFNULL is equivalent to the COALESCE function with two arguments
For additional information, see NULLIF and COALESCE.
Example
SELECT IFNULL(NULL, 'abc') IFNULL_1, IFNULL('xyz', 'abc') IFNULL_2;
Result:
|
IFNULL_1 |
IFNULL_2 |
|---|---|
|
abc |
xyz |