SQL Interview Questions: The Complete 2026 Guide with 200+ Curated Problems by Topic, Difficulty and Company
This guide is the index for everything we know about SQL interviews — what gets asked, how it gets graded, and where to practise it. We map every common question pattern (joins, window functions, CTEs, ranking, gap-and-island) to the exact lessons and runnable scenarios on this site, and we tell you how the bar shifts from a beginner screen to a staff-level system-design round. Read top-to-bottom for a structured prep plan, or jump to your target company or difficulty level.
Last updated · SQL Practice Online team
How to use this guide
SQL interviews are unusually predictable. The same six or seven question patterns show up across every analyst, data-engineer and backend role: filter & aggregate, join with conditions, window-function ranking or running totals, CTE-based step-by-step transforms, gap-and-island sessionisation, and one or two query-optimisation discussions. The bar varies — junior screens stop at GROUP BY; senior loops add execution plans and indexing — but the core vocabulary does not.
This guide is structured so you can prep in any order. If you have a date for an Amazon interview, jump to the Amazon hub. If you know your weak spot is window functions, jump to that scenario category. If you are starting from scratch, follow the level ladder: Level 1 → Level 4 covers 80% of what an analyst loop will throw at you, Level 5 → Level 7 covers senior IC and TL interviews, and Level 8 → Level 10 is staff-and-above territory.
The seven SQL interview question patterns
After grading several hundred candidate sessions, every "new" SQL interview question fits into one of seven shapes. Memorise the pattern and the answer template falls out automatically.
| Pattern | Tell-tale wording | Right tool | Drill it here |
|---|---|---|---|
| Filter & aggregate | "How many...", "average...", "per region" | GROUP BY + HAVING | /scenario/aggregations |
| Conditional join | "...with their manager", "orders and the customer who placed them" | INNER / LEFT JOIN | /scenario/joins |
| Top-N per group | "top 3 products in each category" | ROW_NUMBER() / RANK() in CTE | /scenario/ranking-nth-value |
| Period-over-period | "month-over-month growth", "change vs previous" | LAG() / LEAD() | /scenario/ctes-window |
| Gap-and-island / sessions | "consecutive logins", "user sessions" | Window function + island detection | /scenario/ctes-window |
| Deduplicate / latest record | "most recent address per customer" | ROW_NUMBER() OVER (PARTITION BY) | /scenario/finding-duplicates |
| Hierarchy / self-join | "manager chain", "category tree" | Recursive CTE or self-join | /scenario/self-joins-hierarchical |
Prep by difficulty level: from screening to staff
We grade interview questions on a 10-point ladder that mirrors what real loops ask. The bar moves not just in question difficulty but in expected discussion depth — a Level 7 candidate is expected to talk about index design and write the same query, a Level 1 candidate is just expected to write it.
| Level | Target role | What they ask | Practise here |
|---|---|---|---|
| Level 1 — Beginner | BI analyst trainee, intern | SELECT, WHERE, basic aggregates | /interview/level-1-beginner |
| Level 2 — Junior | Junior analyst | INNER JOIN, GROUP BY, ORDER BY | /interview/level-2-junior |
| Level 3 — Intermediate | Analyst | LEFT/RIGHT JOIN, subqueries, CASE | /interview/level-3-intermediate |
| Level 4 — Mid-level | Senior analyst, junior DE | CTEs, basic window functions, deduplication | /interview/level-4-mid-level |
| Level 5 — Senior | Senior analyst, mid DE | All window functions, complex CTEs, optimisation 101 | /interview/level-5-senior |
| Level 6 — Expert | Senior data engineer | Recursive CTEs, performance reasoning, query plans | /interview/level-6-expert |
| Level 7 — Architect | Staff DE, tech lead | Index design, partitioning strategy, schema trade-offs | /interview/level-7-architect |
| Level 8 — Principal | Principal engineer | Distributed query semantics, transaction isolation | /interview/level-8-principal |
| Level 9 — Distinguished | Distinguished IC | Storage engines, MVCC, concurrency control | /interview/level-9-distinguished |
| Level 10 — Master | Database internals, founder-level | Query optimiser internals, custom storage | /interview/level-10-master |
Prep by question type
Most SQL interviews are coding rounds, but they are not all coding. The seven question types we see in the wild — and how to prepare for each — are:
- Query-based (write the SQL): the canonical coding problem; biggest payoff for time spent.
- Scenario-based: ambiguous business prompt, you ask clarifying questions then write SQL — common at FAANG and high-bar startups.
- Output-prediction: given a schema and a query, predict the result set — checks if you actually understand JOIN semantics and NULL behaviour.
- Debugging: given a broken query, find and fix the bug — favoured by Microsoft and SQL-heavy data-engineering roles.
- Optimisation: given a working query, make it 10× faster — paired with index design at L5+.
- Multiple-choice and true/false: knowledge screens; common in third-party platforms and HR-led screens.
- Communication prompts: explain a concept (window functions, MVCC) in plain English — hybrid IC + manager interviews.
Browse a curated bank of each type at /interview/topic — pick one type per practice session and run 5 problems back-to-back.
Prep by company: 8 hubs of real, sourced questions
Each company hub below collects publicly reported SQL interview questions from that company's loops, mapped to the exact pattern (from the seven above) and to a runnable problem you can solve in the editor. Companies are listed in rough order of how SQL-heavy their interviews tend to be.
- Amazon — heavy on optimisation, joins and aggregations against retail-style schemas. /company/amazon
- Google — leans into window functions, gap-and-island, and ambiguous scenario prompts. /company/google
- Meta — analytics SQL, A/B-test result interpretation, funnel queries. /company/meta
- Microsoft — debugging round is common; expect output-prediction and CTE-heavy problems. /company/microsoft
- Apple — schema-design discussion plus moderate query difficulty. /company/apple
- Netflix — analytics-heavy; window functions and event-stream sessionisation. /company/netflix
- Uber — geospatial and time-series flavoured queries; high bar on optimisation. /company/uber
- Airbnb — funnel analysis, cohort queries, marketplace ranking. /company/airbnb
Prep by topic: 14 scenario categories
If your weak spot is a specific topic — joins, ranking, dates — drill that scenario category until you can write the answer template from muscle memory. Each category has 10–25 progressive problems, beginner to advanced, with runnable solutions.
| Category | Questions | Difficulty | Direct link |
|---|---|---|---|
| SELECT statements | 15 | Beginner | /scenario/select-statements |
| WHERE clause & filtering | 15 | Beginner | /scenario/where-clause |
| Aggregations (GROUP BY, HAVING) | 20 | Beginner → Intermediate | /scenario/aggregations |
| ORDER BY & sorting | 15 | Beginner | /scenario/order-by-sorting |
| LIMIT & OFFSET | 15 | Beginner | /scenario/limit-offset |
| Basic SQL functions | 15 | Beginner | /scenario/basic-functions |
| Finding duplicates | 15 | Intermediate | /scenario/finding-duplicates |
| Ranking & nth-value | 15 | Intermediate → Advanced | /scenario/ranking-nth-value |
| CASE statements | 15 | Intermediate | /scenario/case-statements |
| Joins | 25 | Beginner → Advanced | /scenario/joins |
| Self-joins & hierarchical | 15 | Advanced | /scenario/self-joins-hierarchical |
| Subqueries | 12 | Intermediate → Advanced | /scenario/subqueries |
| CTEs & window functions | 10 | Advanced | /scenario/ctes-window |
| Date operations | 15 | Intermediate | /scenario/date-operations |
Five sample problems with answer templates
1. Second-highest salary (the canonical screen question)
WITH ranked AS (
SELECT salary,
DENSE_RANK() OVER (ORDER BY salary DESC) AS r
FROM employees
)
SELECT DISTINCT salary FROM ranked WHERE r = 2;2. Customers who placed orders in two consecutive months
WITH monthly AS (
SELECT customer_id, DATE_TRUNC('month', order_date) AS m
FROM orders
GROUP BY customer_id, DATE_TRUNC('month', order_date)
),
paired AS (
SELECT customer_id, m,
LAG(m) OVER (PARTITION BY customer_id ORDER BY m) AS prev_m
FROM monthly
)
SELECT DISTINCT customer_id
FROM paired
WHERE m = prev_m + INTERVAL '1 month';3. Top 3 products by revenue per category
WITH ranked AS (
SELECT category_id, product_id, SUM(line_total) AS revenue,
RANK() OVER (PARTITION BY category_id ORDER BY SUM(line_total) DESC) AS r
FROM order_items
GROUP BY category_id, product_id
)
SELECT * FROM ranked WHERE r <= 3;4. Detect 3+ consecutive login days (gap-and-island)
WITH d AS (
SELECT user_id, login_date,
login_date - INTERVAL '1 day' * ROW_NUMBER() OVER (
PARTITION BY user_id ORDER BY login_date
) AS grp
FROM logins
)
SELECT user_id, MIN(login_date) AS streak_start, COUNT(*) AS streak_len
FROM d
GROUP BY user_id, grp
HAVING COUNT(*) >= 3;5. Manager chain (recursive CTE)
WITH RECURSIVE chain AS (
SELECT employee_id, manager_id, 1 AS depth
FROM employees
WHERE employee_id = :start_id
UNION ALL
SELECT e.employee_id, e.manager_id, c.depth + 1
FROM employees e
JOIN chain c ON e.employee_id = c.manager_id
)
SELECT * FROM chain;A four-week structured prep plan
- Week 1 — Fundamentals review: SELECT, WHERE, JOIN, GROUP BY, ORDER BY. 30 problems from /scenario/select-statements, /scenario/where-clause, /scenario/aggregations.
- Week 2 — Intermediate patterns: subqueries, CASE, deduplication, basic ranking. 30 problems from /scenario/subqueries, /scenario/case-statements, /scenario/finding-duplicates, /scenario/ranking-nth-value.
- Week 3 — Advanced patterns: window functions, CTEs, self-joins, recursive CTEs. 25 problems from /scenario/ctes-window and /scenario/self-joins-hierarchical, plus the entire window-functions module at /learn/window-functions.
- Week 4 — Company-specific drilling: pick your target hub (Amazon, Google, Meta, etc.) and run 20 problems back-to-back, talking through your reasoning out loud. End each session with one optimisation/explain-plan question from /interview/level-5-senior or above.
What interviewers actually grade (and what trips up candidates)
- Correctness on edge cases: ties, NULLs, empty result sets. The single biggest cause of fail.
- Readable structure: prefer CTEs over deeply nested subqueries; one transformation per CTE.
- Stating assumptions out loud: "I am assuming order_date is never null" — interviewers want to hear this.
- Knowing when JOIN vs EXISTS vs IN matters and when it does not.
- For senior roles, talking through the execution plan: is this an index seek? Hash join? Sort merge? What changes if the table is 1B rows?
Practice this in the editor
- Browse all SQL interview questions/sql-interview-questions
- Amazon SQL questions/company/amazon
- Google SQL questions/company/google
- Meta SQL questions/company/meta
- Microsoft SQL questions/company/microsoft
- Apple SQL questions/company/apple
- Netflix SQL questions/company/netflix
- Uber SQL questions/company/uber
- Airbnb SQL questions/company/airbnb
- Level 1 — Beginner/interview/level-1-beginner
- Level 4 — Mid-level/interview/level-4-mid-level
- Level 5 — Senior/interview/level-5-senior
- Level 7 — Architect/interview/level-7-architect
- Joins scenarios (25 problems)/scenario/joins
- Ranking & nth-value scenarios/scenario/ranking-nth-value
- CTEs & window functions scenarios/scenario/ctes-window
- Self-joins & hierarchical/scenario/self-joins-hierarchical
Frequently asked questions
How many SQL questions are typically asked in an interview?
Most coding rounds include 1–3 SQL problems in a 45–60 minute window. A junior screen is usually one problem with follow-ups; a senior loop typically has two coding rounds plus one schema/optimisation discussion. Plan to write 3–5 queries per hour of interview time, including the conversation around each.
What are the most common SQL interview questions?
The seven recurring patterns are: filter & aggregate, conditional joins, top-N per group, period-over-period change (LAG/LEAD), gap-and-island sessionisation, deduplication keeping the latest record, and hierarchy/manager-chain via recursive CTE or self-join. About 90% of real interview questions reduce to one of these seven shapes.
Do I need to know window functions for SQL interviews?
For any role above junior analyst — yes. Window functions (ROW_NUMBER, RANK, LAG, LEAD, SUM OVER) are the dividing line between "writes basic SQL" and "writes analytical SQL", and they are explicitly tested at Level 4 and above. If you can confidently solve top-N per group and period-over-period problems, you have cleared the bar for most analyst and data-engineer interviews.
How is SQL graded differently for senior vs junior roles?
Junior interviews grade correctness and basic syntax. Senior interviews grade everything junior plus: readable structure (CTEs over nested subqueries), edge-case handling (NULLs, ties, empty inputs), and an articulated reasoning about indexes and execution plans. At Level 5+, you are expected to discuss how the query plan changes with data scale; at Level 7+, you are expected to design the schema and indexes.
Are FAANG SQL interviews harder than other companies?
The questions themselves are not categorically harder — they map to the same seven patterns. What is harder is the clarifying-question stage and the trade-off discussion. FAANG loops weight ambiguity tolerance and communication heavily; a candidate who writes a perfect query in silence often loses to one who writes a slightly messier query while talking through the assumptions and edge cases.
How long should I prepare for a SQL interview?
For a target role within your current band, plan 3–4 weeks of focused prep at 1–2 hours per day. For a stretch role (one band up), plan 6–8 weeks. The four-week plan in this guide is calibrated for the typical analyst-to-senior-analyst or junior-DE-to-mid-DE jump.
Should I memorise SQL interview questions and answers?
No — but you should memorise answer templates for the seven recurring patterns. Once the templates are muscle memory ("top-N per group always means ROW_NUMBER in a CTE filtered to <= N"), every new question becomes a trivial substitution exercise. Memorising specific question/answer pairs from leaked question banks gets candidates flagged in pattern-detection at FAANG.