MySQL NULLIF() function
NULLIF() function
MySQL NULLIF() returns NULL when the first is equal to the second expression, otherwise, it returns the first expression.
Syntax:
NULLIF(expression1, expression2);
Arguments
Name | Description |
---|---|
expression1 | An expression. |
expression2 | An expression. |
MySQL Version: 5.6
Example: MySQL NULLIF() function
In the following MySQL statement since expressions are equal, it returns NULL.
Code:
SELECT NULLIF(2,2);
Sample Output:
mysql> SELECT NULLIF(2,2); +-------------+ | NULLIF(2,2) | +-------------+ | NULL | +-------------+ 1 row in set (0.03 sec)
Example : MySQL NULLIF() function with unequal arguments
In the following MySQL statement since expressions are not equal, it returns the first expression, i.e. 2.
Code:
SELECT NULLIF(2,3);
Sample Output:
mysql> SELECT NULLIF(2,3); +-------------+ | NULLIF(2,3) | +-------------+ | 2 | +-------------+ 1 row in set (0.00 sec)
Previous:
IFNULL()
Next:
MySQL String Functions ASCII
Inviting useful, relevant, well-written and unique guest posts
- New Content published on w3resource :
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework