In this guide, we will explain 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 is:
NULLIF( expression1, expression2 )
Parameters or Arguments
expression1 and expression2Two 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 :
- 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 NULLIF function examples and explore how to use the NULLIF function.
For example:
mysql> SELECT NULLIF('adglob.in', 'adglob.in'); Result: NULL mysql> SELECT NULLIF('adglob.in', 'baldevinfo.com'); Result: 'adglob.in' mysql> SELECT NULLIF(5, 5); Result: NULL mysql> SELECT NULLIF(5, 6); Result: 5
Next Topic : Click Here
Pingback: MySQL: LAST_INSERT_ID Function | Adglob Infosystem Pvt Ltd