SQL Interview Questions
Practice window functions, join fanout, NULL-safe anti-joins, retention cohorts, composite indexes, and transaction isolation with free SQL interview questions. Each exercise includes hints and a checked query.
Practice questions
- Top two order amounts per customer, keeping ties · window functions · 15 min
- How do you keep customers with no paid orders? · Outer joins · 6 min
- Why can NOT IN return no rows? · NULL and anti-joins · 7 min
- When should you filter with WHERE or HAVING? · GROUP BY and HAVING · 6 min
- Why does joining payments and tickets inflate revenue? · Join cardinality · 9 min
- How do you count successes and unknowns in one query? · Conditional aggregates · 7 min
- How do you get one latest event per user? · Deterministic window order · 8 min
- How do you reset a running total every month? · Running totals and frames · 9 min
- How do you calculate day-one retention from repeated events? · Signup cohorts · 10 min
- Why did our composite index still scan too many rows? · Composite indexes · 10 min
- Two withdrawals both read balance 100. How do you stop overdrafts? · Transaction isolation · 12 min
- Why did UNIQUE(email, deleted_at) still allow duplicate active users? · Unique constraints · 10 min
- How do you split user events into sessions using LAG()? · LAG and sequence gaps · 10 min
How to practice
Predict the result or explain what you would change before opening the hints. Then compare your reasoning with the answer and try the follow-up question.