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: 8.0
Example: MySQL NULLIF() function
In the following MySQL statement since expressions are equal, it returns NULL.
Code:
SELECT NULLIF(2,2);
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);
Output:
mysql> SELECT NULLIF(2,3); +-------------+ | NULLIF(2,3) | +-------------+ | 2 | +-------------+ 1 row in set (0.00 sec)
Previous: IFNULL()
Next: MySQL String Functions ASCII
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join