Mysql Nullif Function

MySQL: NULLIF Function

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

Description

The MySQL NULLIF function returns NULL if two expressions are equivalent. Otherwise, it returns the first expression.

Syntax

The syntax for the NULLIF function in MySQL is:

NULLIF( expression1, expression2 )

Parameters or Arguments

expression1 and expression2

Two expressions to test if equivalent expression1 = expression2.

Note

  • The NULLIF function will return NULL, if expression1 = expression2 (equal).
  • The NULLIF function will return expression1, if expression1 != expression2 (not equal).

Applies To

The NULLIF 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.15

Example

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

For example:

mysql> SELECT NULLIF('AODBA.com', 'AODBA.com');
Output: NULL

mysql> SELECT NULLIF('AODBA.com', 'mysite.com');
Output: 'AODBA.com'

mysql> SELECT NULLIF(5, 5);
Output: NULL

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