Skip to main content
Compares two expressions. Returns <expression1> if it’s non-NULL, otherwise returns <expression2>.

Syntax

Parameters

Return Types

Same as input type

Remarks

Use ZEROIFNULL(<expression>) as a synonym shorthand for IFNULL(<expression>, 0). IFNULL(a, b) has the same behaviour as COALESCE(a, b).

Examples

The following example shows the core behavior: IFNULL returns the original value when it is non-NULL, and returns the replacement when it is NULL:

Rows: 5Execution time: 4.15ms

The following example uses IFNULL to replace the nextlevel value with 0 for the final level in the levels table, which has no next level (NULL):

Rows: 10Execution time: 6.00ms