SQLite nullif() Function
The SQLite nullif()
function returns NULL
if both parameters are the same, otherwise returns the first argument.
Syntax
Here is the syntax of the SQLite nullif()
function:
nullif(expr1, expr2)
Parameters
expr1
-
Required. A value or expression.
expr2
-
Required. Another value or expression.
Return value
If the two arguments are the same, expr1 = expr2
, the SQLite nullif()
function returns NULL
, otherwise it returns expr1
.
Examples
This example illustrates the ifnull()
basic usage of the SQLite function:
SELECT
nullif(1, 1),
nullif(1, 2);
nullif(1, 1) =
nullif(1, 2) = 1
nullif()
is equivalent to CASE WHEN expr1 = expr2 THEN NULL ELSE expr1 END
, as follows:
SELECT
CASE WHEN 1 = 1 THEN NULL ELSE 1 END,
CASE WHEN 1 = 2 THEN NULL ELSE 1 END;
CASE WHEN 1 = 1 THEN NULL ELSE 1 END =
CASE WHEN 1 = 2 THEN NULL ELSE 1 END = 1