The MySQL NULLIF() function returns NULL if expr1 equals expr2; otherwise returns expr1. It allows developers to perform deterministic data transformations directly within SQL queries.
EXPRESSIONNULL if any required input argument evaluates to NULL.expr1, expr2-- Query demonstrating MySQL NULLIF() usage in production queries
SELECT NULLIF(status, 'DRAFT') AS status_check FROM posts;
| status_check |
|---|
| NULL |
IFNULL() or COALESCE() if your input columns allow NULL values.WHERE clauses disables B-tree index lookups (causing full table scans). Use generated columns with indexes when querying heavily.Write a SQL query using NULLIF() to format or evaluate data retrieved from a database table.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With