MySQL IFNULL() Function
The IFNULL() function is used to check if the first expression is NULL. If it is NULL, it returns the value of the second parameter; if it is not NULL, it returns the value of the first parameter.
The syntax for the IFNULL() function is:
IFNULL(expression, alt_value)
If the expression in the first argument is NULL, it returns the alternative value from the second argument.
Parameter Description:
Parameter | Description |
---|---|
expression | Required, the value to test |
alt_value | Required, the value to return if the expression is NULL |
Examples
First argument is NULL:
SELECT IFNULL(NULL, "tutorialpro");
The output for the above example is:
tutorialpro
First argument is not NULL:
SELECT IFNULL("Hello", "tutorialpro");
The output for the above example is:
Hello