This tutorial explains how to use the MySQL NULLIF function with syntax and examples.
The MySQL NULLIF function returns NULL if two expressions are equivalent. Otherwise, it returns the first expression.
The syntax for the NULLIF function in MySQL is:
NULLIF( expression1, expression2 )
Two expressions to test if equivalent expression1 = expression2.
The NULLIF function can be used in the following versions of MySQL:
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