Skip to content

Tracks · SDE-1, SDE-2, Senior

SQL for interviews

This track takes you from a single table to a full SQL round. You first learn how tables, keys and indexes work. Then you write queries step by step: filters, joins, groups, subqueries and window functions. You learn the patterns that come back in many rounds, and how to speak while you write. You finish with a mock SQL round with an AI interviewer.

  • 20steps in 6 stages
  • 6 h 15 minin total
  • 2 weeksat 4 hours a week

Start here if you have a SQL round coming, or if joins, GROUP BY and window functions still feel unsure.

Skip this track if your rounds have no SQL. Use the SDE-1 track for the basics of data and indexes.

The track has 13 lessons, 3 trade-offs, 4 practice steps. Steps marked “Free account” are inside the app.

Stage 1 of 6 · 2 h 16 min

Tables, keys and indexes

You know how tables link by keys, why an index makes a query fast, and what a transaction keeps safe.

  1. Lesson

    SQL or NoSQL, and which kind

    How to choose a database from the way your app uses its data: the five kinds of database, what each is good at, and what each costs.

    24 min
  2. Lesson

    Data modelling: tables, relationships, normal forms

    How to turn requirements into tables: find the entities, decide how they link, draw them, and keep each fact in one place with the first three normal forms.

    24 min
  3. Trade-off

    Normalize vs denormalize

    When to keep each fact in one place and when to copy it on purpose, with the read-to-write numbers that decide it.

    13 min
  4. DrillFree account

    The orders screen reads 100 rows for 20 orders

    Practise this decision: copy the data or join the tables. Seven minutes.

    7 min
  5. Lesson

    Indexes and reading a query plan

    Why an index makes a query fast, how a B-tree and a composite index work, when an index hurts, and how to read EXPLAIN to find out what the database really does.

    25 min
  6. Trade-off

    Add an index vs full table scan

    When to add a database index and when a full table scan is the better plan, the numbers that decide, and what each choice costs on reads and writes.

    14 min
  7. DrillFree account

    My last 10 orders takes about 8 seconds

    Practise this decision: add an index or leave the scan. Seven minutes.

    7 min
  8. Lesson

    Transactions: ACID and isolation levels

    What a transaction promises (ACID), how isolation levels decide what two users doing things at the same time can see, and the bugs that appear when you choose the wrong level.

    22 min

Stage 2 of 6 · 1 h 2 min

Read and filter rows

You can read a table, filter and sort rows, and handle missing values and dates without a silent wrong answer.

  1. Lesson

    SQL basics: SELECT, WHERE, ORDER BY and LIMIT

    Read a table, ask it a plain question, and get the rows back in the right order, with the traps of AND and OR, text dates, case, and whole-number division.

    22 min
  2. Lesson

    SQL values: NULL, COALESCE, CASE and dates

    Handle missing values and dates without silent wrong answers: what NULL really is, IS NULL, COALESCE, NULLIF, CASE, and the date functions of SQLite.

    21 min
  3. Trade-off

    Offset vs cursor pagination

    When to page a long list with offset and when with a cursor, with row counts, the shifting-page problem and the index you need.

    12 min
  4. DrillFree account

    The last pages of the order list take 5 seconds

    Practise this decision: offset or cursor paging, with worked numbers. Seven minutes.

    7 min

Stage 3 of 6 · 39 min

Join and group rows

You can join tables without losing or doubling rows, and count or total rows in groups.

  1. Lesson

    SQL joins: inner, left, anti-join and self-join

    Combine tables with INNER and LEFT JOIN, keep or drop unmatched rows on purpose, find rows with no match, compare rows of one table with a self-join, and avoid the fan-out trap.

    21 min
  2. Lesson

    SQL groups: GROUP BY, HAVING and conditional counts

    Summarise rows per group with COUNT, SUM, AVG, MIN and MAX; filter groups with HAVING; count only what matches a rule; and find duplicates.

    18 min

Stage 4 of 6 · 40 min

Queries inside queries

You can use a subquery or a CTE, walk down a tree of rows, and use window functions for ranks and running totals.

  1. Lesson

    SQL queries inside queries: subqueries, EXISTS, CTEs and recursion

    Put one query inside another, test for rows that exist or do not exist, build a long query in named steps with WITH, stack results, and use recursion for days, numbers and trees.

    20 min
  2. Lesson

    SQL window functions: ranks, running totals, LAG and frames

    Add a calculation over a group of rows without losing the rows: totals and shares beside each row, ranks, running totals, LAG and LEAD, and moving averages with frames.

    20 min

Stage 5 of 6 · 45 min

Patterns that rounds repeat

You know the usual recipes: top N per group, the latest row, duplicates, medians, streaks, sessions, cohorts and funnels.

  1. Lesson

    SQL patterns that interviews repeat

    Recipes for the questions that come back in every SQL round: top N per group, the latest row, duplicates, medians, the price on a date, running balances, shares of a total and pairs.

    21 min
  2. Lesson

    SQL patterns for time: streaks, sessions, cohorts, funnels and rolling windows

    Recipes for questions about days and order of events: login streaks and gaps, sessions, cohorts and retention, funnels, rolling windows, spikes, and year over year.

    24 min

Stage 6 of 6 · 54 min

Say it in the round

You can run a SQL round in a fixed order, explain your query aloud, and answer the question about speed.

  1. Lesson

    Speaking in a SQL round: ask, check, then make it fast

    Run a SQL interview in a fixed order: ask questions, build and check the query step by step, explain it aloud, and answer the speed question with an index and a query plan.

    25 min
  2. SQL mockCheckpointFree account

    SQL mock interview

    Your checkpoint: write and explain a query with an AI interviewer, then answer a question about speed.

    29 min

Estimates

How the time is counted

These times are planning estimates, not deadlines. Yours will vary.

  • Lessons and trade-off pages: the number of words divided by 130, rounded, plus 4 minutes to think.
  • A Drill: about 7 minutes. A system design mock: allow about 45 minutes. A machine coding mock: allow about 75 minutes.
  • Other mocks: a SQL mock with one problem, about 29 minutes. A behavioural mock, about 36 minutes. A resume mock, about 35 minutes. A coding mock, about 45 minutes.
  • A simulator level or a Cost Lab workload: allow about 15 minutes. This is our own estimate for a first try. It can take you less or more.
  • Incident investigation: time varies. The room has a simulated clock; your real time depends on how you investigate. It has no fixed time, so it is not counted in any total.
  • The total is the sum of all steps that have a time. The weeks are the hours divided by 4, rounded up. We assume 4 hours a week, like a person with a job. Doing a step again is not counted.

Ready for the checkpoint?

The last step is a mock interview with an AI interviewer. It gives you a report that shows what you did well and what was missing.