Skip to main content
Version: V1.0.0

IFNULL

Syntax

IFNULL(expr1, expr2)

Description

The IFNULL() function returns expr1 if expr1 is not NULL; otherwise, it returns expr2. The return value of IFNULL() is a number or string, depending on the context in which it is used.

The default return type of IFNULL() is determined as follows:

ExpressionReturn type
expr1 or expr2 returns a string.String
expr1 or expr2 returns a floating-point value.Float
expr1 or expr2 returns an integer.Integer

If both expr1 and expr2 are strings and either of them is case-sensitive, the result is case-sensitive.

Examples

SELECT IFNULL('abc', null), IFNULL(NULL+1, NULL+2), IFNULL(1/0, 0/1);
+---------------------+------------------------+------------------+
| IFNULL('abc', null) | IFNULL(NULL+1, NULL+2) | IFNULL(1/0, 0/1) |
+---------------------+------------------------+------------------+
| abc | NULL | 0.0000 |
+---------------------+------------------------+------------------+
1 row in set (0.001 sec)