SQL Interview Questions: 2026 Guide to 414 Published Problem Guides

Use this guide to review recurring SQL problem patterns and move into the platform's current lesson and practice collections. The catalog contains 414 public problem guides, including 386 exercises available in the current workspace. Each collection below shows published and runnable counts separately, so a public guide is never mistaken for an executable exercise.

Last updated · SQL Practice Online team

How to use this guide

Many SQL interview exercises use recurring patterns: filter and aggregate, join with conditions, window-function ranking or running totals, CTE-based transforms, gap-and-island sessionisation, and query-optimisation discussions. The exact format and evaluation criteria vary by role and interviewer, so treat these as preparation patterns rather than a guarantee about a particular hiring process.

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, begin with Interview Mode’s Beginner Foundation, then drill one question-type track at a time.

The seven SQL interview question patterns

The seven shapes below organize common practice patterns in this curriculum. They are useful starting points, but prompts can combine patterns and still require independent reasoning about grain, NULLs, ties, and business rules.

PatternTell-tale wordingRight toolDrill 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
The seven recurring patterns and where to drill them.

Prep by question type: from foundation to focused practice

Interview Mode starts with Beginner Foundation, then lets candidates focus by question type. This keeps the answer pattern consistent while difficulty still increases inside each track.

TrackWhat it trainsTypical promptsPractise here
Beginner FoundationOnboarding across every answer typeOne simple question per format/interview
Query WritingExecutable SQL correctnessSELECT, JOIN, GROUP BY, windows/interview
DebuggingRoot-cause analysisBroken SQL plus corrected query/interview
Output PredictionManual result reasoningPredict exact rows from sample data/interview
OptimizationPerformance trade-offsPick/refine the better query/interview
Plan ReviewExecution-plan reasoningFind bottleneck and practical fix/interview
DDL DesignSchema designTables, keys, constraints, defaults/interview
ValidationResult-based correctnessCompare business rule to query output/interview
Track-based SQL interview practice.

Prep by question type

SQL preparation can include coding and non-coding formats. The platform supports the following practice formats:

  • Query-based (write the SQL): execute a query and assess its result against the authored task.
  • Scenario-based: interpret a business prompt, state assumptions, and write SQL.
  • Output-prediction: given a schema and a query, predict the result set — checks if you actually understand JOIN semantics and NULL behaviour.
  • Debugging: identify the demonstrated defect in a broken query and propose a correction.
  • Optimisation: compare valid approaches and explain evidence-based performance trade-offs.
  • Multiple-choice and true/false: check focused SQL knowledge and semantics.
  • Communication prompts: explain a concept such as window functions or transaction isolation in plain English.

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 independent company-style hubs

Each hub contains independent, company-style practice built around a familiar product or marketplace domain. These are illustrative exercises, not claims that a company asked a particular question or uses a particular hiring bar. Published guides and currently runnable exercises are counted separately.

  • Apple — Independent Apple-style product, retail, services, support, workforce, and device-usage SQL practice. 20 published guides; 18 runnable now. /company/apple
  • Amazon — Independent Amazon-style e-commerce, warehouse, inventory, and customer analytics SQL practice. 24 published guides; 22 runnable now. /company/amazon
  • Google — Independent Google-style search, advertising, user-engagement, and video-product SQL practice. 29 published guides; 26 runnable now. /company/google
  • Microsoft — Independent Microsoft-style cloud, productivity, subscription, usage, support, and customer analytics SQL practice. 30 published guides; 25 runnable now. /company/microsoft
  • Meta — Independent Meta-style social-product, engagement, content, community, messaging, and advertising SQL practice. 23 published guides; 23 runnable now. /company/meta
  • Netflix — Independent Netflix-style streaming, subscription, catalog, ratings, and engagement SQL practice. 25 published guides; 22 runnable now. /company/netflix
  • Airbnb — Independent Airbnb-style marketplace, booking, listing, payment, review, and guest analytics SQL practice. 25 published guides; 24 runnable now. /company/airbnb
  • Uber — Independent Uber-style mobility marketplace SQL practice covering trips, drivers, riders, pricing, payments, and promotions. 19 published guides; 19 runnable now. /company/uber

Prep by topic: 15 scenario collections

If your weak spot is a specific topic — joins, ranking, or dates — use the matching collection for focused practice. Across 15 collections, the catalog currently provides 219 published guides and 207 runnable exercises.

CategoryPublished guidesRunnable nowDifficultyDirect link
SELECT Statements23 published12 runnableBeginner/scenario/select-statements
WHERE Clause & Filtering12 published12 runnableBeginner to Advanced/scenario/where-clause
LIMIT & OFFSET7 published7 runnableBeginner to Advanced/scenario/limit-offset
Basic SQL Functions13 published13 runnableBeginner to Advanced/scenario/basic-functions
ORDER BY & Sorting15 published15 runnableBeginner to Advanced/scenario/order-by-sorting
SQL Joins16 published16 runnableBeginner to Advanced/scenario/joins
SQL Subqueries12 published12 runnableBeginner to Advanced/scenario/subqueries
CTEs & Window Functions11 published11 runnableBeginner to Advanced/scenario/ctes-window
SQL Aggregations16 published15 runnableBeginner to Advanced/scenario/aggregations
Ranking & NTH Value17 published17 runnableIntermediate to Advanced/scenario/ranking-nth-value
Finding Duplicates & Data Quality12 published12 runnableBeginner to Advanced/scenario/finding-duplicates
CASE Statements & Conditional Logic13 published13 runnableBeginner to Advanced/scenario/case-statements
Database Changes10 published10 runnableBeginner to Hard/scenario/database-changes
Date Operations & Time-Based Analytics26 published26 runnableEasy to Hard/scenario/date-operations
Self Joins & Hierarchical Queries16 published16 runnableAdvanced/scenario/self-joins-hierarchical
All 15 scenario collections, derived from the public catalog.

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;
Robust to ties — uses DENSE_RANK so multiple "second highest" salaries are returned together.

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 Optimization or Plan Review question from Interview Mode.

What to check in your own SQL answers

  • Correctness on edge cases: ties, NULLs, empty result sets, duplicates, and boundary dates.
  • Readable structure: prefer CTEs over deeply nested subqueries; one transformation per CTE.
  • Stating assumptions explicitly, such as whether order_date may be NULL.
  • Knowing when JOIN vs EXISTS vs IN matters and when it does not.
  • For performance discussions, explaining the evidence you would inspect in an execution plan and how data scale could change the trade-offs.

Practice this in the editor

Frequently asked questions

How many SQL questions are typically asked in an interview?

Interview formats vary by employer and role. Ask the recruiter about duration, number of exercises, SQL dialect, editor access, and whether the round includes debugging, design, or optimisation discussion. Practise under a timer only after you can solve the relevant pattern accurately.

What are the most common SQL interview questions?

Useful recurring practice patterns include filter and aggregate, conditional joins, top-N per group, period-over-period change with LAG or LEAD, gap-and-island sessionisation, deterministic deduplication, and hierarchy traversal. A real prompt may combine several patterns.

Do I need to know window functions for SQL interviews?

Window functions are important for analytical SQL. Learn ROW_NUMBER, RANK, LAG, LEAD, aggregate windows, partitioning, ordering, and explicit frames. Confirm the expectations for your target role rather than assuming every interview requires the same depth.

How is SQL graded differently for senior vs junior roles?

Evaluation varies. A sound preparation rubric checks result correctness, readable structure, edge cases such as NULLs and ties, stated assumptions, and—when the prompt asks for it—reasoning about indexes, execution plans, and data scale. Follow the authored prompt instead of assuming an unstated technique is mandatory.

Do company-style practice hubs reproduce real interview questions?

No. The company hubs on this site are independent, illustrative exercises using familiar product and marketplace domains. They are not claims about a company's private question bank, interview frequency, grading process, or hiring bar.

How long should I prepare for a SQL interview?

Preparation time depends on your starting point, target role, and interview format. Use the four-week plan as an adjustable sequence, measure accuracy on the relevant patterns, and spend more time on weak areas rather than treating the schedule as a hiring guarantee.

Should I memorise SQL interview questions and answers?

No. Learn reusable reasoning patterns, then check each new prompt for result grain, ties, NULLs, duplicates, date boundaries, and explicitly required techniques. A familiar pattern is a starting point, not proof that the same template is correct for every dataset.