General
SQL NULL vs empty string vs zero
0 views

NULL Is Not Zero, Not an Empty String, and Not False
This single idea explains most NULL-related surprises: NULL represents an unknown or missing value — not zero, not an empty string, not boolean false. It's a placeholder meaning "there is no value here to compare," and that has real consequences for how comparisons behave.
SELECT * FROM Employees WHERE salary = NULL; -- returns ZERO rows, always, for every row in the table
SELECT * FROM Employees WHERE salary IS NULL; -- correctly returns Dave
SELECT * FROM Employees WHERE salary IS NOT NULL; -- everyone except Dave
salary = NULL doesn't mean "salary is unset" — it asks "is salary equal to this unknown value," and the honest answer to that question is always "unknown," never "yes." SQL has no way to spell "compare to NULL and get true" using =; IS NULL / IS NOT NULL are dedicated operators that exist precisely because equality can't do this job.
For more like this, visit: https://codeoath.in/blog/sql-null-joins-aggregates
Read original: https://dev.to/nexus_vibes/sql-null-vs-empty-string-vs-zero-3jlo
PreviousSQL Joins in PostgreSQL: Patients, Doctors, and the Rows That Go MissingNextSQL vs NoSQL: Kenapa PostgreSQL Masih Jadi 'Swiss Army Knife' di 2026
Related posts
GUI64 – GUI for the Commodore 64 running on top of the built-in ROM
0Hacker News New
I checked whether my laptop is wasting RAM
0Hacker News New
3rd-party statistically-correct benchmarks comparing WebAssembly runtimes
0Hacker News New
Au High Court to consider whether under-16s social media ban is unconstitutional
0Hacker News New
An Existential Guide To: Flirting
0Hacker News New
Dampe RNG has been solved for Ocarina of Time
0Hacker News New