SQL: NULLIF reference
19 March 2023 (Updated 19 March 2023)
On this page
In a nutshell
The NULLIF
function compares two expressions and returns NULL
if they’re both equal or the first expression they aren’t equal. You can use NULLIF
to handle special cases where you might want to return NULL
if two values match.
Syntax
NULLIF(expression1, expression2)
Example
SELECT NULLIF(column1, 0) as result
FROM my_table;
Here, NULLIF
will compare the value of column1
with 0
for every table row. If they are equal, NULL
is returned. Otherwise, column1
is returned.
Tagged:
MySQL
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment