Skip to content

NULLIF

NULLIF compares two expressions. If they are equal, it returns NULL; otherwise, it returns the first expression.

Syntax

NULLIF(expression1, expression2)

Examples

Return NULL when both expressions are equal:

SELECT NULLIF(0, 0) AS result;

Return the first expression when the two expressions are different:

SELECT NULLIF('hello', 'helle') AS result;

This returns hello.

Notes

NULLIF requires exactly two arguments.