SQL practice: every exercise, sorted by level and topic

150 practice problems across 54 lessons, starting with your very first SELECT. You write every query yourself, run it on a real database in the browser and find out right away whether the result is right.

The short version: each exercise is a small task from office life, run against the database of an online office supplies store. Write a query, run it as often as you like, then have it checked. Nothing to install, no sign-up needed, with hints and a worked solution.

Start right now: three warm-up problems

The first filters customers by city, the second fills in missing phone numbers, the third pulls the latest orders. All three are free. If you solve them without a hint, feel free to jump to a later topic in the list below.

Task Sales is planning visits in Boston. From the customers table, show the columns name and phone, but only for customers whose city is Boston.

customers 12 rows, 7 columns
customer_idnamecitycountrycustomer_sincesegmentphone
1Harbor Fremont PartnersBostonUSA2021-03-15Business617-555-0142
2Emily CarterChicagoUSA2022-07-01ConsumerNULL
3Riverside County OfficeRiversideUSA2020-11-20Government951-555-0110
4Raj PatelLeedsUK2023-01-09Consumer0113 496 0123
5Lakeview Hotel LtdManchesterUK2022-04-18Business0161 496 0456
6Olivia BrooksAustinUSA2024-02-27ConsumerNULL
7Greene & Shaw LLPLondonUK2021-09-05Business020 7946 0321
8Maple Grove High SchoolAustinUSA2023-08-14School512-555-0187
9Chloe EvansBostonUSA2025-05-30Consumer617-555-0199
10Northline Printing CoTorontoCanada2020-06-12Business416-555-0133
11Daniel KimSeattleUSA2024-10-03ConsumerNULL
12Westbrook Dental ClinicChicagoUSA2022-12-01Business312-555-0164

Task Sales wants a phone list: show the name and phone of every customer. Where no number is on file, the list should say no number instead of leaving the cell blank.

customers 12 rows, 7 columns
customer_idnamecitycountrycustomer_sincesegmentphone
1Harbor Fremont PartnersBostonUSA2021-03-15Business617-555-0142
2Emily CarterChicagoUSA2022-07-01ConsumerNULL
3Riverside County OfficeRiversideUSA2020-11-20Government951-555-0110
4Raj PatelLeedsUK2023-01-09Consumer0113 496 0123
5Lakeview Hotel LtdManchesterUK2022-04-18Business0161 496 0456
6Olivia BrooksAustinUSA2024-02-27ConsumerNULL
7Greene & Shaw LLPLondonUK2021-09-05Business020 7946 0321
8Maple Grove High SchoolAustinUSA2023-08-14School512-555-0187
9Chloe EvansBostonUSA2025-05-30Consumer617-555-0199
10Northline Printing CoTorontoCanada2020-06-12Business416-555-0133
11Daniel KimSeattleUSA2024-10-03ConsumerNULL
12Westbrook Dental ClinicChicagoUSA2022-12-01Business312-555-0164

Task The dashboard should show the three most recent orders. Show order_id, order_date and status for those three orders, newest first.

orders 18 rows, 5 columns
order_idcustomer_idorder_datestatusemployee_id
100112026-01-08delivered3
100242026-01-12delivered4
100332026-01-20delivered3
100472026-02-03delivered4
100522026-02-11cancelled8
100612026-02-25delivered3
1007102026-03-04delivered2
100852026-03-17delivered4
100982026-03-30delivered3
101062026-04-07delivered8
1011122026-04-22delivered4
101232026-05-06delivered3
101392026-05-19cancelled8
101472026-06-02shipped4
101512026-06-10shipped3
1016112026-06-12openNULL
101742026-06-13openNULL
1018102026-06-14openNULL

How the SQL exercises work

The tables you need are shown above the editor, with every column. Tap a table or column name to insert it instead of typing. Press Run (or Ctrl+Enter) to see your result as a table straight away. Run as often as you want: every query works on a fresh copy of the data, so there is nothing to break.

Check compares your result with the result of the model answer: same columns in the same order, same rows, same values. Row order only matters when the task asks for sorting. How you write the query is up to you. IN or two ORs, upper or lower case, an alias or none: if the result is right, the task is solved. The one exception is a keyword the exercise is there to practice, such as LIMIT. That one has to be in your query.

A second check on different data

Once your result is right, your query runs again on a slightly changed database you never see: a customer has moved, a price has changed, a row has been added. The model answer runs on the same data. Say the task asks for all open orders and you copy the order numbers from the result into WHERE order_id IN (1016, 1017, 1018) instead of filtering on status. That gets caught here, and the message tells you your query only works with this particular data and asks whether a value is hard-coded.

Messages, hints and solutions

When something is off, the exercise tells you as precisely as it can: one column too many, a row missing, the wrong sort order, a typo in a column name with a suggestion for the right one, a stray comma before FROM. Common database errors come with a plain-English pointer to where to look.

If you get stuck, three hints reveal a little more each time: first the idea, then the structure, then an almost finished query. The model answer, with an explanation of why it works, appears only when you ask for it.

Points

Solving an exercise for the first time earns points, more for harder tasks and projects. Using a hint halves them, and revealing the solution means none for that exercise. With a free account your points, solved exercises and learning streak are saved across all your devices.

All SQL practice problems by level and topic

The lessons follow the learning path of the SQL course. Each page explains its topic with examples and has several exercises that get harder as you go. Every level ends with a project.

Level 1: Getting started

Level 2: Summarizing data

Level 3: Joining tables

Level 4: Changing data and building tables

Level 5: Advanced queries

Level 6: Real work and final test

Bonus: Database design

Bonus: Performance

Bonus: Recursive queries and upserts

How to get the most out of practice

  • Run before you check. Look at your result before pressing Check. You will spot plenty of mistakes yourself: a missing column, a list that is too long, a sort that runs the wrong way.
  • Start small. Begin with SELECT * FROM table to get to know the data, then add WHERE, ORDER BY and the columns you need one step at a time.
  • Read the task closely. It names the columns in the order it wants them and says whether to sort. Words like “at least” or “up to” mean the boundary value is included.
  • Try without a hint first. A couple of failed attempts is normal and part of learning. Reach for a hint when you are genuinely stuck.
  • Come back later. With an account, “Review today” brings back exercises you solved a while ago. What still works after a few days is what sticks.

Practice problems with solutions, built for doing

Every task has a model answer. It does not sit next to the task, though. It comes from the server only when you ask for it. That is on purpose: if you read the answer first, you mostly just copy it and can't reproduce it a week later. If you try it yourself and read the error messages along the way, more of it stays. After revealing a solution, it pays to solve the same exercise again a few days later without help.

For ready-made queries to read and adapt, sorted by everyday tasks such as “revenue by month” or “customers with no orders”, see SQL query examples. For interview-style practice problems sorted by difficulty and topic, with a stopwatch, try SQL 50.

FAQ

Does every SQL exercise come with a solution?

Yes. Each task has a model answer and an explanation of why it works and what a typical wrong answer does differently. Before that, you can ask for three hints. Your query can look different from the model answer as long as the result matches.

Is SQL practice here free?

Partly. All level 1 exercises, including the level 1 project, are free, and so is the first exercise of every lesson from level 2 on. The remaining exercises and the projects from level 2 on are part of Premium. Every lesson is free to read.

How hard are the problems?

Level 1 assumes nothing beyond knowing what a table is. Within each lesson the tasks get harder, and the last one usually combines the new topic with something you already know. The project at the end of each level is a bigger task that brings several topics together.

Do I need to install MySQL or another database?

No. The exercises run on a SQLite database on our server, so all you need is a browser, even on your phone. Most queries are written the same or almost the same way in MySQL, PostgreSQL and SQL Server. Where they differ, the lesson says so.

Can I break the database?

No. Every query runs on a fresh copy of the practice data, and the query exercises only accept statements that don't change anything.

Is my progress saved?

With a free account, yes. The learning path then shows a check mark next to every lesson you have finished. Your browser also keeps the query you were working on, even without an account.

Completely new to SQL?

Start with lesson 1. It explains tables, rows, columns and keys, and a few minutes in you will write your first query.

Start lesson 1 Go to the SQL course

Write to us

Choose language

Select your preferred language