What does SELECT * FROM users WHERE deleted_at = NULL return?
Options
- Users with deleted_at NULL
- No rows (Correct option)
- All rows
- An error in all databases
Answer
No rows
Why
NULL means 'unknown'. Comparing anything with unknown gives unknown, even NULL = NULL. WHERE keeps only rows where the condition is TRUE, so no rows match.
The correct way is WHERE deleted_at IS NULL (or IS NOT NULL).
Remember
Use IS NULL, never = NULL.