MySQL IFNULL() Function
Example
Return an alternative value IF the expression is NULL:
SELECT IFNULL(NULL, "W3Schools.com");
Try it Yourself »
Definition and Usage
The IFNULL() function lets you return an alternative value if an expression is NULL.
If expression is NOT NULL, the IFNULL() function returns expression.
Syntax
IFNULL(expression, alt_value)
Parameter Values
Parameter | Description |
---|---|
expression | Required. The value to test whether is NULL |
alt_value | Required. The value to return if expression is a NULL value |
Note
- The IFNULL() function returns the alt_value, if the expression is a NULL
- The IFNULL() function returns the expression, if the expression is NOT NULL
Technical Details
Works in: | MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23 |
---|
More Examples
Example
Return an alternative value IF the expression is NULL:
SELECT IFNULL("Hello", "W3Schools.com");
Try it Yourself »
Example
Return an alternative value IF the expression is NULL:
SELECT IFNULL(NULL, 500);
Try it Yourself »