Database
SQL NULL vs empty string vs zero
NeXusVibes Dev.to (EN Zone)
2 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
← Previous
Caso de éxito: los toolkits gráficos
Next →
The AI-in-QA Decision Framework, With Real Prompts
Related
Comments0
No comments yet — be the first