Querydrill

Drill the SQL interviews actually ask.

Querydrill is SQL practice in your browser. Every exercise gives you real tables, a question and an editor. You write the query, run it as often as you like, and it is checked on the rows it returns and again on a changed copy of the data, so guesses fail and working queries pass.

  • SELECT, WHERE, ORDER BY and CASE
  • GROUP BY, HAVING and date grouping
  • Inner, left and self joins
  • Subqueries, CTEs and window functions
  • Interview classics like nth highest salary
  • Work mode on messy, real-world tables

60 exercises6 levels6 free, no sign-up

A stopwatch made of paper cards with a table unfolding from it and three check marks
Two copies of a table, the second with changed rows marked in red, and a magnifier between them

Checked twice, like a real reviewer would.

  1. 01
    Write the querySee the sample tables, type SQL, run it as often as you like.
  2. 02
    It runs on two datasetsThe sample data, and a copy with new rows and changed values.
  3. 03
    You learn whyIt names the mistake: a join that duplicates rows, an inner join that drops them, integer division, a typed-in value. Hints and a worked solution follow.

Six levels, from first SELECT to real work on messy data.

12BasicsSELECT, WHERE, ORDER BY, LIMIT, DISTINCT, IN, LIKE, NULL handling and CASE.
13AggregationCOUNT, SUM, AVG, GROUP BY, HAVING, COUNT DISTINCT and grouping by dates.
12JoinsInner, left and self joins, finding rows with no match, keeping zero counts.
12AdvancedSubqueries, CTEs, RANK, DENSE_RANK, ROW_NUMBER, LAG and running totals.
4Interview classicsNth highest salary, earns more than the manager, pivots with CASE.
7Work modeRequests from Marketing, Finance and Support on messy tables: text amounts, mixed date formats, duplicates and stray spaces.

SQL practice that checks your result, not your wording

Plenty of SQL practice sites compare your query to a reference string, or hand you an answer key next to the question. You peek, you paste, you move on, and a week later you still freeze at a LEFT JOIN. Querydrill was built around one rule: the only way through an exercise is a query that returns the right rows.

Every exercise runs your query twice. First on the sample tables you can see, then on a copy with extra rows and changed values. A query that types in today's numbers or names passes the first run and fails the second, and you are told so. That is the same test an interviewer applies when they ask what happens if the data changes.

Practice SQL online, with nothing to install

The database runs inside your browser, so there is no server to set up and no account to create before your first query. The exercises stick to standard SQL that works the same way in PostgreSQL, MySQL, SQLite and BigQuery, apart from the occasional date function, which the prompt points out.

That makes Querydrill useful in the places a real database is awkward: on a laptop between meetings, on a train, or in the ten minutes before a technical screen. Progress is saved in your browser, and a free account keeps it across devices.

SQL exercises built in six levels

The 60 exercises are organized into levels, and each level only adds one or two ideas on top of what you already know.

  • Basics: picking columns, filtering rows, sorting on two columns, pattern matching, NULL handling and labels with CASE.
  • Aggregation: customers per country, spend per customer, repeat buyers, revenue by month, first and last order, HAVING.
  • Joins: orders with customer names, customers who never ordered, employee and manager, products never sold, keeping zero counts.
  • Advanced: subqueries, CTEs, rank within department, running totals, change from the previous order with LAG, top two per category.
  • Interview classics: second and third highest salary, earns more than the manager, departments above average, pivoting statuses with CASE.
  • Work mode: cleaning a country report, finding duplicate accounts, totalling revenue stored as text, signups per plan on messy data.

Within a level the exercises get harder one notch at a time. By the end of Joins you have written a self join, found the rows with no match and kept the zero counts a careless inner join would have dropped, not because you read about it, but because the exercise would not pass until you did.

Open the exercise list

SQL interview questions, practiced the way they are asked

Most data analyst and data engineer interviews include a live SQL round, and the questions repeat: the nth highest salary, employees who earn more than their manager, each customer's first order, month over month growth, a running total. They are not hard once you have written them a few times. They are hard the first time, with someone watching.

The Interview classics level collects those questions, the Advanced level covers the window functions behind them, and timed mode puts a clock on each exercise with hints and solutions locked until time is up. Run through the top three levels the week before an interview and the live round feels like one more drill.

Try a timed exercise

SQL joins practice and window functions practice

Two topics cause most of the failed queries at work, so they get more exercises than anything else.

  • Joins practice: inner versus left, a join that silently duplicates rows, customers from the same country, products per order, headcount per department with departments that have nobody.
  • Window functions practice: RANK and DENSE_RANK, ROW_NUMBER to pick the top earner per department, LAG for the change from the previous period, SUM OVER for running totals and share of revenue.
  • Subqueries and CTEs: above the average salary, big spenders, each customer's first order, written both ways so you can see which reads better.

SQL for data analysts: the questions a manager actually asks

The tables in every exercise look like something you would meet in a job: customers, orders, products, employees with managers, payments with plans. The questions are the ones that land in an analyst's inbox: revenue per country, average paid order, hires per year, customers active in several months.

The Work mode level goes one step further. The data arrives the way it does in real life, with amounts stored as text, mixed date formats, duplicate accounts and stray spaces, and the request comes from Marketing, Finance or Support. Cleaning the data is part of the answer, as it is at work.

Learn SQL by getting it wrong first

A hint is one click away, but the worked solution opens only after your second attempt. That is on purpose. Running a query, seeing twice as many rows as expected, reading the hint and fixing the join yourself is the part that sticks. Copying a solution before you have tried does not.

When a query fails, the feedback names the kind of mistake: a join that duplicates rows, an inner join that drops them, integer division, a typed-in value, a GROUP BY that is missing a column. Every exercise also explains why the reference query is built the way it is.

Why hands-on beats watching

You can watch a ten-minute video on window functions and feel like you understand them. Then you open an editor, type OVER ( and stop. The gap between recognizing and producing is the whole problem, and the only thing that closes it is reps.

A Querydrill session is five to fifteen minutes of writing queries, each one slightly different from the last. Ten sessions in, the join syntax, the GROUP BY rules and the window clauses are automatic.

SQL exercises for beginners and for people who query every day

If you have never written a query, the Basics level starts with SELECT and WHERE and does not assume anything. If you already write SQL every day, skip to Advanced, Interview classics or Work mode and look for the gaps: most experienced users have one or two constructs they have always avoided, and the drills find them quickly.

Every exercise is independent, so you can jump to the one you need for today's problem and come back to the rest later.

Timed mode, like the live round.Each exercise gets a clock. Hints and solutions stay locked until time is up, and your best times are kept.

The same data in Python.Our sister site Pandasdrill drills the same kind of analysis in pandas, with real Python running in your browser. Try Pandasdrill

Try the first six exercises free.

No sign-up needed for the first six, including one Work mode task. If it works for you, Pro unlocks all 60, and a free account saves your progress across devices.

Start practicing free

Start free. Pay once you are hooked.

Free

$0
  • 6 exercises, including a Work mode task
  • Instant checking and hints
  • Timed mode
Start free

Pro

All 60
  • Every level, including window functions, CTEs and Work mode
  • Worked solutions and explanations
  • Progress and best times saved to your account

You create a free account first, so Pro is attached to it.

Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.

Questions

Which SQL does it use?

SQLite, running in your browser. The exercises stick to standard SQL that works the same way in PostgreSQL, MySQL and BigQuery, apart from the date function noted in the prompt.

Why did my query fail when the result looked right?

Every answer is also run on a changed copy of the tables with extra rows and updated values. A query that types in today's numbers or names passes the first run and fails the second. That is the same test an interviewer applies when they ask what happens if the data changes.

Which topics are covered?

SELECT, WHERE, ORDER BY, LIMIT, DISTINCT, IN, LIKE, NULL handling, CASE, COUNT, SUM, AVG, GROUP BY, HAVING, inner, left and self joins, subqueries, CTEs, RANK, DENSE_RANK, ROW_NUMBER, LAG, running totals, pivots with CASE, and cleaning text amounts, dates and duplicates.

Is there a free version?

The first six exercises are free without an account, including one Work mode task. Pro unlocks the other 54 for $12 a month or $79 once.

Can I use it to prepare for a SQL interview?

Yes. The Interview classics and Advanced levels cover the questions most live rounds use, and timed mode lets you practice against the clock with hints switched off.

How do I cancel the monthly plan?

Open Account and choose Cancel subscription. You keep Pro until the end of the period you paid for and are not charged again. If Pro is not for you, you get a full refund within 14 days of paying.

What if my answer is right but marked wrong?

Answers are checked on the rows they return, not on how the query is written, so any correct query passes, and columns in a different order are accepted too. If a check still gets it wrong, use the report link under the result. Reports are reviewed, and a check that is wrong gets fixed.