sajad torkamani

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