Databases · Middle · Question 30 of 75
Why can WHERE id NOT IN (SELECT user_id FROM bans) return no rows at all?
- ✓Correct answer: If the subquery returns a NULL,
NOT INcan never be true, so every row is filtered out;NOT EXISTSavoids this - 2Because
idmust be indexed - 3
NOT INdoesn't work with subqueries
Explanation
x NOT IN (1, NULL) means x <> 1 AND x <> NULL, and the second part is unknown. This is a classic bug with nullable columns.