Stop 15 · Interview PreparationTopics · 7/10

Explaining Your Query Out Loud

Part of the SQL Roadmap

In short

In a live SQL round, a silent correct answer often scores lower than a clearly explained one with a small slip. Interviewers are hiring how you think, not just what you type.

Interviewers care about your reasoning as much as the final query. Talking through assumptions, the table grain and edge cases shows you can be trusted with real data.

The jaadu sits in a commentary box high above a sunny cricket ground, microphone in one hand, pointing excitedly at the pitch with the other.

Think of it like this

The cricket commentator

A good commentator doesn't just say 'four runs'. They explain the field placing, why the bowler went short and what the batter read early. Viewers follow every ball even if they've never played. Explaining a query is the same job: say what you're about to do, why, and what you expect to see, so the interviewer follows every step.

Watch it happen

The first two minutes of a live round

Interviewer
You

Top 3 customers by revenue in each city

1/5The question arrives. Don't start typing yet.

The big ideas

What you need to know

Clarify first

Ask about definitions, time ranges, ties, NULLs and duplicates. Two good questions beat a fast wrong answer.

Say the grain

'One row per order' or 'one row per user per day'. It shows you know what joins and sums will do.

Plan in steps

Describe the CTEs in order before writing them: filter, aggregate, rank, pick.

Check out loud

Walk one example through your query and mention what could go wrong, like empty cities or ties.

How it works

A talk track for any SQL question

  1. 1

    Restate

    Repeat the question in your own words to confirm you heard it right.

  2. 2

    Clarify

    Ask about definitions, time window, ties and NULLs.

  3. 3

    Grain

    Say what one row means in each table you'll use.

  4. 4

    Plan

    Outline the steps, usually as CTEs, before writing code.

  5. 5

    Write and verify

    Write it, then trace one small example and name the edge cases.

See it in code

Walk through the code

sql
1-- Clarified: revenue = delivered orders only, quarter = Jul to Sep 20262-- Grain: orders has one row per order3WITH customer_revenue AS (4  SELECT c.city, c.customer_id, c.full_name,5         SUM(o.amount) AS revenue6  FROM orders o7  JOIN customers c ON c.customer_id = o.customer_id8  WHERE o.status = 'delivered'9    AND o.order_date >= DATE '2026-07-01'10    AND o.order_date <  DATE '2026-10-01'11  GROUP BY c.city, c.customer_id, c.full_name12),13ranked AS (14  SELECT *,15         DENSE_RANK() OVER (PARTITION BY city ORDER BY revenue DESC) AS rnk16  FROM customer_revenue17)18SELECT city, full_name, revenue, rnk19FROM ranked20WHERE rnk <= 321ORDER BY city, rnk;

1/4Say your assumptions and the grain first. If one is wrong, the interviewer corrects you before you've written anything.

Runs in PostgreSQL and MySQL 8. The comments at the top are what you say before typing. Many interviewers are happy to see them written in the editor too.

Save yourself the pain

Common mistakes

Oops

Typing in silence for ten minutes, then explaining at the end.

Do this instead

Talk as you go. If you're heading the wrong way, the interviewer can nudge you early.

Oops

Assuming what 'revenue' or 'active user' means.

Do this instead

Ask. Then write the assumption as a comment so it's visible.

Your mission

Record yourself

~30 min

Quick check

What should you usually do first when given a live SQL question?

Go deeper

  1. 1Record yourself solving a problem and explaining each step.
  2. 2Start answers by restating the question and asking about edge cases.
  3. 3Practise mock interviews with a friend.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge