NULLIF() in MySQL — How It Works

What the MySQL NULLIF() function does, with an example.

Published October 22, 2026

NULLIF() returns NULL if two expressions are equal, otherwise returns the first expression.

Key points

  • Part of standard SQL functions available in MySQL for working with query results

Example

SELECT NULLIF(quantity, 0) FROM inventory;
More SQL articles