w3resource

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

Previous: ltrim()
Next: quote()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/sqlite/core-functions-nullif.php