- Categories:
IFNULL¶
If expr1
is NULL, returns expr2
, otherwise returns expr1
.
- Aliases
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 asUNION
,INTERSECT
,EXCEPT
, andMINUS
. 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¶
The collation specifications of all input arguments must be compatible.
The collation of the result of the function is the highest-precedence collation of the inputs.
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] | --------+--------+-------------+-------------+