MySQL | NULLIF( ) Function
Last Updated :
19 May, 2021
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 expression 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
Share your thoughts in the comments
Please Login to comment...