SQLite nullif() function
Description
The nullif() function returns its first argument if the arguments are different and NULL if the arguments are the same.
Syntax:
nullif(X,Y);
Arguments:
Name | Description |
---|---|
X | An expression. |
Y | An expression. |
SQLite Version: 3.8.5
Example: SQLite nullif() function
In the following SQLite statement since expressions are equal, it returns NULL.
SELECT nullif(2,2);
Here is the result.
Sample Output:
nullif(2,2) ------------------------------
Example: SQLite nullif() function with unequal arguments
In the following SQLite statement since expressions are not equal, it returns the first expression, i.e. 2.
SELECT nullif(2,3);
Here is the result.
Sample Output:
nullif(2,3) ------------------------------ 2
Example: SQLite nullif() function using table
Sample table: departments
Sample table: employees
If you want to search, which department_id of the departments table does not exists into the employees table or does not matching with the department_id of the employees table, the following SQL can be used.
SELECT nullif((SELECT department_id FROM departments),(SELECT department_id FROM employees));
Here is the result.
Sample Output:
nullif((SELECT department_id FROM departments),(SELECT department_id FROM employees)) ------------------------------------------------------------------------------------- 10
- 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
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook