IFNULL
Description
If the value of <expr1> is not NULL, returns <expr1>; otherwise, returns <expr2>.
Alias
- NVL
Syntax
IFNULL(<expr1>, <expr2>)
Parameters
<expr1>: The expression to be checked forNULL.<expr2>: The value to return if<expr1>isNULL.
Return Value
- If
<expr1>is notNULL, returns<expr1>. - Otherwise, returns
<expr2>.
Examples
- Example 1
SELECT IFNULL(1, 0);+--------------+| IFNULL(1, 0) |+--------------+| 1 |+--------------+
- Example 2
SELECT IFNULL(NULL, 10);+------------------+| IFNULL(NULL, 10) |+------------------+| 10 |+------------------+
- Both arguments are NULL
SELECT IFNULL(NULL, NULL);+--------------------+| IFNULL(NULL, NULL) |+--------------------+| NULL |+--------------------+