Back to Practice
#0354
Avoid NOT IN With NULL Trap
MediumSQL24 min20 XP
Problem
Return customer_id values from customers that are not present in blocked_customers, even if blocked_customers contains NULL.
Why This Matters
SQL interviews usually test whether you can turn a business question into the right rows, grouping level, join type, and edge-case behavior.
Schema
customers(customer_id INTEGER); blocked_customers(customer_id INTEGER)
Examples
Example 1
Inputblocked list contains 2 and NULL
Output1 and 3
NOT EXISTS is not poisoned by NULL values in the blocked table.
Constraints
- Return only the requested columns.
- Use deterministic ORDER BY when multiple rows are returned.
- Assume SQLite-compatible SQL unless the prompt states otherwise.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core SQL case
Inputblocked list contains 2 and NULL
Expected[[1],[3]]
NOT EXISTS is not poisoned by NULL values in the blocked table.
Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks