SQLite: nullif Function
This SQLite tutorial explains how to use the SQLite nullif function with syntax and examples.
Description
The SQLite nullif function returns NULL if two expressions are equivalent. Otherwise, it returns the first expression.
Syntax
The syntax for the nullif function in SQLite is:
nullif( expression1, expression2 )
Parameters or Arguments
- expression1 and expression2
- Two expressions to test if equivalent,
expression1 = expression2
.
Note
- The nullif function will return NULL, if expression1 = expression2 (equal).
- The nullif function will return expression1, if expression1 != expression2 (not equal).
Applies To
The nullif function can be used in the following versions of SQLite:
- SQLite 3.8.6, SQLite 3.8.x, SQLite 3.7.x, SQLite 3.6.x
Example
Let's look at some SQLite nullif function examples and explore how to use the nullif function in SQLite.
For example:
sqlite> SELECT nullif('techonthenet.com', 'techonthenet.com'); Result: NULL sqlite> SELECT nullif('techonthenet.com', 'checkyourmath.com'); Result: 'techonthenet.com' sqlite> SELECT nullif(1, 1); Result: NULL sqlite> SELECT nullif(1, 2); Result: 1
Advertisements