Interview Preparation
Intermediate 14 min read Interview Preparation

SQL Interview Prep

The patterns interviewers test every time

SQL screens are the highest-repetition test in analytics. The winning prep is drilling the patterns — joins, aggregates, window functions, CTEs — until they are reflex, on a real environment with a clock.

SQL interviewjoinswindow functionsCTEsscreeningdrill
Before we start

What you will learn

  • Identify the five patterns behind most SQL screen questions
  • Practice window functions and CTEs under time pressure
  • Talk about your SQL approach while typing
Introduction

What is this?

SQL screens reduce to a handful of patterns: filters and aggregates, joins with grain control, deduplication and ranking (window functions), rolling/time-window calculations, and conditionals for segments. Interviewers watch your approach as much as the output — clean, spoken, correct SQL earns double credit.

Motivation

Why do you need it?

  • Most analyst jobs live and die on SQL daily.
  • Window functions are the single differentiator between junior and mid SQL answers.
  • Screens are timed and typed, so practice must be too.
Think about it

Mental model

Imagine

A musician practicing scales

Think of

An analyst drilling SQL patterns

Scales are unglamorous, but fluency at speed is what lets you perform under pressure; SQL patterns are the scales of the analysis trade.

Mechanics

How it works

  • Learn the five pattern families and which question each maps to.
  • Drill on a real warehouse or SQLite against a database with data.
  • Practice narrating your approach: read the question, state the join, explain the window.
  • Review each attempt for the elegant versus merely-working solution.

Five families of SQL questions cover most screen prompts.

Filter
Join
Rank
Window
Segment
Real world

In production

  • A 'top 5 products per category' prompt is a row_number window answer.
  • A 'new vs returning users' prompt is a first-purchase CTE plus a join.
  • A cumulative-revenue prompt is a SUM() OVER (ORDER BY date).
Guidelines

Best practices

  • Restate the question and grain before typing a single word.
  • Use CTEs to keep logic legible; interviewers read along.
  • Mention edge cases (NULLs, duplicates) even if you do not code them.
Watch out

Common mistakes

  • Joining without thinking about row multiplication — then wondering why counts tripled.
  • Using GROUP BY when the ask is a keep-one-row-per-group window question.
  • Going silent: the reviewer cannot see your reasoning if you do not speak it.
When things break

Debugging tips

  • If your answer misses rows, re-read whether the ask wants ALL groups (LEFT JOIN) or only matches.
  • If distinct counts look wrong, suspect a fan-out join and check the grain before aggregating.
Interviews

Interview checkpoint

Test yourself

Quick quiz

0/2
1

Top-N per group is answered with

2

A running total over time uses

Go deeper

Official documentation