Categories:
Conditional Expression Functions

IFNULL

If expr1 is NULL, returns expr2, otherwise returns expr1.

Aliases:NVL

Syntax

IFNULL( <expr1> , <expr2> )

Arguments

expr1
A general expression.
expr2
A general expression.

Usage Notes

  • Either expression can include a SELECT statement containing set operators, such as UNION, INTERSECT, EXCEPT, and MINUS. When using set operators, make sure that data types are compatible. For details, see the General Usage Notes in the Set Operators topic.

Collation Details

Examples

SELECT a, b, IFNULL(a,b), IFNULL(b,a) FROM i;

--------+--------+-------------+-------------+
   a    |   b    | ifnull(a,b) | ifnull(b,a) |
--------+--------+-------------+-------------+
 0      | 5      | 0           | 5           |
 0      | [NULL] | 0           | 0           |
 [NULL] | 5      | 5           | 5           |
 [NULL] | [NULL] | [NULL]      | [NULL]      |
--------+--------+-------------+-------------+