SQL · Queries that survive scale
What are common SQL mistakes in production?
Short answer
Common mistakes include SELECT *, NOT IN with NULLs, missing join conditions, non-sargable predicates, incorrect grouping, deep OFFSET, and over-indexing without measuring.
Most SQL bugs are not syntax errors. They are semantic mistakes that return plausible but wrong results, or performance mistakes that only appear at scale. Reviewing queries for these patterns catches many production incidents early.
SELECT *
FROM orders o, customers c
WHERE o.customer_id = c.id
AND c.status != 'blocked';Frequent offenders
- NOT IN with a nullable subquery returning no rows
- Using = NULL instead of IS NULL
- Forgetting a join condition and producing a Cartesian product
- Filtering the right table in WHERE after a LEFT JOIN, turning it into an inner join
- Selecting non-aggregated columns that are not grouped
- Applying functions to indexed columns, which blocks normal index use
- Using deep OFFSET instead of keyset pagination
- Using SELECT * in production paths, wasting I/O and breaking on schema changes
- Over-indexing write-heavy tables or assuming every index is used
- Ignoring transaction scope and holding locks during slow external calls
A useful review habit is to ask three questions: what is the grain of each row, which rows are preserved by each join, and what happens when a column is NULL. Those questions catch many correctness bugs before performance even matters.
SELECT id
FROM users u
WHERE NOT EXISTS (
SELECT 1
FROM bans b
WHERE b.user_id = u.id
);Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Why can NOT IN return no rows?
- 2How does a missing join condition affect the result?
- 3Why is DISTINCT a poor fix for duplicate rows?
- 4What is the risk of SELECT * in application code?
Say it in the interview
The mistakes I see most are semantic: NOT IN with NULLs, = NULL, missing join conditions, and filtering the wrong side of a LEFT JOIN. Performance mistakes include non-sargable predicates, deep OFFSET, and indexing without measuring. I review queries by checking row grain, preserved rows, and NULL behavior. If I see duplicates, I fix the join grain rather than hiding them with DISTINCT.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live SQL mock interview and get scored feedback on depth, clarity and confidence.