Skip to content

NULLIF

  • expr1: This is the first expression to be compared in the NULLIF function. It can be a column name, a constant, or the result of another function.
  • expr2: This is the second expression to be compared in the NULLIF function. Like expr1, it can also be a column name, a constant, or the result of another function.
SELECT NULLIF(4,4), NULLIF(5,4);
+-------------+-------------+
| NULLIF(4,4) | NULLIF(5,4) |
+-------------+-------------+
| NULL | 5 |
+-------------+-------------+

In the example, the function NULLIF compares two expressions. When the expressions are equal, the function returns NULL. In the first case, 4 equals 4, so NULL is returned. In the second case, 5 does not equal 4, so 5 is returned.