Mysql Ifnull Function

MySQL: IFNULL Function

This tutorial explains how to use the MySQL IFNULL function with syntax and examples.


The MySQL IFNULL function allows you to return an alternate value if an expression is NULL.


The syntax for the IFNULL function in MySQL is:

IFNULL( expression, value_if_null )

Parameters or Arguments


The value to test as NULL.


The value to return if expression is NULL.


  • The IFNULL function will return expression, if expression is NOT NULL.
  • The IFNULL function will return value_if_null, if expression is NULL.
  • The IFNULL function is similar to the Nz function in MSAccess.

Applies To

The IFNULL function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23


Let's look at some MySQL IFNULL function examples and explore how to use the IFNULL function in MySQL.

For example:

mysql> SELECT IFNULL('', '');
Output: ''

Output: ''

mysql> SELECT IFNULL(DATE('2014-02-01'), '2014-02-18');
Output: '2014-02-01'

mysql> SELECT IFNULL(DATE(NULL), '2014-02-18');
Output: '2014-02-18'

mysql> SELECT IFNULL(5, 6);
Output: 5

mysql> SELECT IFNULL(5/0, 'Dividing by 0 returns NULL');
Output: 'Dividing by 0 returns NULL'