NULLIF()

Use the nullif() function as shorthand for a searched case statement where two equal expressions return null.

nullif() takes the following syntax. Its two arguments are the expressions that you want to compare.

 nullif(fieldName1, fieldName2)

In this example, the query returns null for all City values that are Aberdeen. If the City value is not Aberdeen, then it returns the City value.

Here’s how to write the query as a case statement.

SELECT CASE WHEN City='Aberdeen'
THEN NULL
ELSE City
END AS City
FROM "Superstore"
GROUP BY City;

Here's how to write the same query using nullif().

SELECT NULLIF(City, 'Aberdeen') as City
FROM "Superstore"
GROUP BY City;

City
Aberdeen
Akron
Albuquerque
Alexandria