Home › Blog › SQL interview questions

SQL interview questions

SQL rounds feel unpredictable and are not. Across data analyst, data engineer and backend loops, the same small set of patterns accounts for most questions - and the follow-up is almost always about making it faster.

The patterns that repeat

PatternTypical questionKey tool
Top N per groupTop 3 products by revenue in each categoryROW_NUMBER / RANK with PARTITION BY
DeduplicationKeep only the latest row per userROW_NUMBER with ORDER BY desc
Running totalsCumulative revenue by daySUM OVER with ORDER BY
Period comparisonMonth-over-month changeLAG / LEAD
Gaps and islandsLongest streak of consecutive active daysRow number difference trick
Conditional aggregationCount of orders by status in one rowSUM with CASE WHEN
Self-joinEmployees earning more than their managerJoin a table to itself
Anti-joinUsers who never orderedLEFT JOIN with NULL check, or NOT EXISTS
If you learn one thing: window functions. Four of the eight patterns above are window functions, and they are the most common reason a candidate stalls in a live SQL round.

The traps

The optimisation follow-up

After you produce a working query, expect "this is slow on a billion rows - what now?" A good answer walks through:

How to practise

Write the eight patterns from memory, without reference, until each takes under two minutes. That is a far better use of time than solving fifty varied problems, because the patterns are what transfer. Then practise saying your approach out loud before typing, since most SQL rounds are live and the interviewer is listening to your reasoning.

Where CoPilot Interview fits

Disclosure: we build an interview assistant, so treat this as a disclosed pitch. CoPilot Interview is a native Windows and macOS app that puts suggested answers on your own screen in about two seconds, across coding, system design and behavioral rounds, with a permanent free tier that needs no credit card.

There is a role page at SQL interview help. The roles that lean hardest on SQL are covered in data engineer interview questions and data analyst interview questions.

Frequently asked questions

What SQL questions are asked in interviews?

Around eight patterns cover most of them: top N per group, deduplication, running totals, period comparison with LAG, gaps and islands, conditional aggregation, self-joins and anti-joins. Four are window functions, which is why window functions are the highest-value thing to drill.

What level of SQL is needed for interviews?

Comfortable with window functions, multiple joins and subqueries, written live without reference. Most candidates can read these constructs but cannot produce them quickly under observation, which is what the round actually tests.

How do you answer the 'make this query faster' question?

Say you would read the execution plan first rather than guessing, then cover indexes on join and filter columns, partition pruning, avoiding functions on indexed columns in WHERE, and filtering or aggregating before joining rather than after.

What is the most common SQL interview mistake?

Join multiplication - a one-to-many join silently inflating aggregates. If a total looks implausibly high, that is almost always the cause. Close behind is NOT IN returning nothing when the subquery contains a null.

Walk into the round with a second pair of eyes

CoPilot Interview is a native Windows and macOS app that puts suggested answers on your own screen in about two seconds, across coding, system design and behavioral rounds. The free tier is permanent: 15 minutes a day, no credit card.

Try it free