Database
SQL NULL vs empty string vs zero
NeXusVibes Dev.to (EN Zone)
29 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
Postgres RLS in Symfony: three green isolation tests, and the UPDATE that moves tenant 1's invoices into tenant 2's books
Database
35
Dev.to (EN Zone)
Turning Mermaid ER diagrams into shareable 3D schema tours
Database
31
DEV Community
finally understand why redis blocks on one slow command, wish I knew this earlier
Database
28
Reddit r/webdev
Tracing Which Internal Consumer Read Each Webhook Event (One Registration, One Queue)
Database
30
DEV Community
Comments0
No comments yet — be the first