IFNULL function [Miscellaneous]

Function

If the first expression is the NULL value, then the value of the second expression is returned. If the first expression is not NULL, the value of the third expression is returned. If the first expression is not NULL and there is no third expression, then the NULL value is returned.

Syntax

IFNULLexpression1, expression2 [ , expression3 ] )

Parameters

expression1 The expression to be evaluated. Its value determines whether expression2 or expression3 is returned.

expression2 The return value if expression1 is NULL.

expression3 The return value if expression1 is not NULL.

Examples

The following statement returns the value -66:

SELECT IFNULL( NULL, -66 ) FROM iq_dummy

The following statement returns NULL, because the first expression is not NULL and there is no third expression:

SELECT IFNULL( -66, -66 ) FROM iq_dummy

Standards and compatibility