SQLNULLIFNULLtutorial

What is NULLIF in SQL? Safe division and cleanup for beginners

NULLIF returns NULL if two values are equal. Plain words: safe division via NULLIF(x, 0), cleaning placeholder values like '' or 'unknown', and pairing with COALESCE for clean data handling. With tables and common pitfalls.

1 min readSQL · NULLIF · NULL · tutorial

NULLIF is the function "if two values are equal, return NULL; otherwise return the first". It's the perfect inverse of COALESCE and shines in two cases: safe division and cleaning placeholder values.

This article is currently in Russian. The full English translation is on the way.

Practice on real tasks

Solve tasks in the SQL trainer with instant grading and hints.

Open trainer