MySQL IFNULL() Function
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