Lesson 9 of 10 · 30 min
The mistakes interviewers see most
By the end of this lesson you can recognise and fix the six mistakes interviewers see most often in SQL answers, and explain in one sentence why each version was wrong.
Every exercise in this lesson is a query a candidate actually wrote in an interview (on Wadi Market's shop data). Each one runs, or nearly runs, and each one looks reasonable. Fix the query, then practise the one-sentence explanation in the exercise's solution: that sentence is what you would say if the interviewer asked “why did you write it that way?”.
The six mistakes, in the order of the exercises:
- *COUNT() after a LEFT JOIN.** The unmatched row counts as 1, so ‘zero’ never appears.
- WHERE instead of HAVING. WHERE runs before grouping, so it cannot see aggregates.
- BETWEEN on timestamps.
BETWEEN '2025-12-01' AND '2025-12-31'stops at midnight at the start of the 31st. - DISTINCT to hide a fan-out. A join multiplied rows;
SUM(DISTINCT …)then drops genuinely equal values, so the total is wrong in a new way. - Averages at the wrong grain. Averaging order lines is not the average order value.
- LIMIT for top-N per group. LIMIT applies to the whole result, not to each group.
This lesson, its 6 graded exercises and every other Members lesson in SQL Quest come with a Formula Quest membership that includes SQL (Single Quest with SQL selected, Quest Trio including SQL, or Quest Unlimited), or with SQL access from your organization.
Free to everyone: all of SQL Foundations and Retrieving and Filtering Data, the first lesson of every track, the playground, the dataset library and the SQL reference. See free lessons