MySQL | NULLIF( ) Function
The MySQL NULLIF() function is used for the comparison of two expressions. The NULLIF() function returns NULL if both the expressions are equal, else it returns the first expression. The NULLIF() function accepts the expressions as parameter and returns NULL if both of them are equal.
Syntax:
NULLIF(expression1, expression2)
Parameters Used:
expression1 – It is used to specify the first expression.
expression2 – It is used to specify the second expression.
Return Value:
The MySQL NULLIF() function returns NULL if both the expressions passed are equal or else it returns the first expresion if both the expressions are not equal.
Supported 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
Example-1: Implementing NULLIF() function by comparing two same strings.
SELECT NULLIF("Geeksforgeeks", "Geeksforgeeks");
Output:
NULL
Example-2: Implementing NULLIF() function by comparing two unequal strings.
SELECT NULLIF("123", "Geeksforgeeks");
Output:
123
Example-3: Implementing NULLIF() function by comparing two integer values.
SELECT NULLIF(2, 4);
Output:
2
Recommended Posts:
- SQL general functions | NVL, NVL2, DECODE, COALESCE, NULLIF, LNNVL and NANVL
- MySQL | MD5 Function
- MySQL | BIN() Function
- MySQL | IF( ) Function
- MySQL | SESSION_USER( ) Function
- MySQL | ISNULL( ) Function
- MySQL | Group_CONCAT() Function
- MySQL | CONNECTION_ID( ) Function
- MySQL | PASSWORD Function
- MySQL | CAST( ) Function
- MySQL | AES_DECRYPT ( ) Function
- MySQL | LEAD() and LAG() Function
- MySQL | DES_DECRYPT ( ) Function
- MySQL | ENCODE( ) Function
- MySQL | USER( ) Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

