Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

MySQL IFNULL() Function

MySQL IFNULL() Function

MySQL Functions MySQL Functions

The IFNULL() function is used to test whether the first expression is NULL. If it is NULL, the value of the second parameter is returned; if it is not NULL, the value of the first parameter is returned.

The syntax of the IFNULL() function is:

IFNULL(expression, alt_value)

If the expression of the first parameter is NULL, the alternate value of the second parameter is returned.

Parameter description:

Parameters Description
expression Required, the value to test
alt_value Required, the value returned when the expression is NULL

Example

The first parameter is NULL:

SELECT IFNULL(NULL, "RUNOOB");

The output of the above example is:

RUNOOB

The first parameter is not NULL:

SELECT IFNULL("Hello", "RUNOOB");

The output of the above example is:

Hello

MySQL Functions MySQL Functions