Understanding NULL in SQL
Understanding NULL in SQL: Common Pitfalls and How to Handle Them NULL is one of the first things every SQL learner meets and one of the last things fully understood. It doesn't mean zero, it doesn't mean empty string, and it doesn't behave like a normal value in comparisons — which is exactly where the bugs come from. ๐ What NULL Actually Means NULL represents the absence of a value — "unknown," not "empty." A NULL phone number isn't the same as an empty string phone number; one means "we don't have this data," the other means "we know it's blank." ๐งช Why NULL = NULL Doesn't Work SELECT * FROM customers WHERE phone = NULL; -- ❌ Always returns zero rows SELECT * FROM customers WHERE phone IS NULL; -- ✅ Correct NULL isn't equal to anything — not even another NULL. In three-valued SQL logic, any comparison involving NULL evaluates to "unknown," not true or false, so the row is excluded either wa...