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 


My Personal Notes arrow_drop_up


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.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.