Querydrill

SQL interview questions, with a live database to run them on

Most SQL interview question lists give you the question and a pasted answer. That does not prepare you for the screen where you have to write it, run it and get the right rows. Every question below opens an exercise with the tables loaded, so you write the query, run it, and get told whether it is right, including on data you cannot see.

What SQL interviews actually test

Across analyst, data engineer and backend screens the question types repeat. Interviewers want to see that you can join without duplicating rows, aggregate with the right GROUP BY, filter aggregates with HAVING, and reach for a window function when a ranking or running total is asked. The hardest questions combine two of these.

  • Filtering and sorting: WHERE with several conditions, IN, LIKE, NULL handling, ORDER BY on two keys, LIMIT.
  • Aggregation: COUNT, SUM, AVG, MIN and MAX with GROUP BY; HAVING to filter groups; COUNT DISTINCT.
  • Joins: inner versus left, finding rows with no match, self-joins for manager and employee, joining three tables.
  • Subqueries and CTEs: rows above the average, the second or third highest value, breaking a query into named steps.
  • Window functions: RANK and DENSE_RANK, running totals, LAG for month-over-month change, share of total.
  • Data cleaning: duplicates, text stored in inconsistent cases, dates stored as strings.

Warm-up questions: SELECT, WHERE, ORDER BY

These are the questions a screen opens with. Get them right fast; interviewers notice hesitation here more than anywhere.

  1. Pick two columns Free
  2. Filter rows Free
  3. Top three earners Free
  4. Each country once Free
  5. Two countries Pro
  6. Pattern match Pro
  7. No manager Pro
  8. Sort on two columns Pro
  9. Label with CASE Pro

GROUP BY and HAVING questions

Count per group, total per group, groups above a threshold. The classic mistake is putting an aggregate condition in WHERE instead of HAVING.

  1. Customers per country Pro
  2. Spend per customer Pro
  3. Repeat buyers Pro
  4. Revenue by month Pro
  5. Average salary per department Pro
  6. Customers who ordered Pro
  7. Average paid order Pro
  8. Hires per year Pro

JOIN questions

"Customers with no orders" is the single most asked SQL interview question; it is a LEFT JOIN with a NULL check, or NOT EXISTS. The self-join (employees and their managers) is the second.

  1. Orders with customer names Pro
  2. Customers who never ordered Pro
  3. Revenue per country Pro
  4. Everyone with a department Pro
  5. Employee and manager Pro
  6. Revenue per product Pro
  7. Products never sold Pro
  8. Orders per customer Pro
  9. Customers from the same country Pro

Subquery and CTE questions

Second highest salary, employees above the average, department above the company average. These separate people who know syntax from people who can decompose a problem.

  1. Above the average salary Pro
  2. Second highest salary Pro
  3. Third highest salary Pro
  4. Big spenders Pro
  5. Earns more than the manager Pro
  6. Departments above average Pro

Window function questions

Rank within a group, running total, month-over-month change with LAG, top two per category, percentage of total. Window functions are what senior screens use to find the ceiling.

  1. Rank within department Pro
  2. Running revenue total Pro
  3. Top earner per department Pro
  4. Dense rank Pro
  5. Change from the previous order Pro
  6. Share of revenue Pro
  7. Each customer's first order Pro
  8. Month over month Pro
  9. Top two per category Pro
  10. Pivot the statuses Pro

Data-cleaning questions

Real screens increasingly hand you a messy table. Finding duplicates, normalizing inconsistent country names, and summing revenue stored as text are all here.

  1. Clean up the country report Free
  2. Find duplicate accounts Pro
  3. Total revenue from text amounts Pro
  4. Revenue by month Pro
  5. Signups per plan Pro
  6. Paying customers by country Pro
  7. First payment per customer Pro

How to prepare in a week

  • Days 1 and 2: Basics and Aggregation until GROUP BY and HAVING are automatic.
  • Days 3 and 4: Joins. Do the no-match and self-join questions until you can write them without thinking.
  • Day 5: Subqueries and CTEs. Rewrite each subquery answer as a CTE and vice versa.
  • Day 6: Window functions. Rank, running total, LAG, top-N per group.
  • Day 7: Timed mode across everything you failed on the first try.

Run the questions on a real database

Six exercises are free without an account. Pro unlocks all 60, with hidden-data checks, hints, worked solutions and progress saved to your account.

Start practicing free

Questions

Which SQL dialect is used?

SQLite, running in your browser. The questions use standard SQL that works unchanged in PostgreSQL, MySQL and SQL Server, including window functions and CTEs.

How are answers checked?

Your query runs against the tables you see and again against a hidden copy with different rows, so a query that only works by coincidence is caught. Row order is checked only when the question asks for it.

Are the answers shown?

A hint is available at any time, and a worked solution opens after two attempts, or straight away once solved. In timed mode both stay closed until the clock runs out.

Is this enough to pass a SQL screen?

It covers the question types that appear in analyst, data engineer and backend screens. Pair it with practice explaining your query out loud, since most interviews ask you to talk through it.