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_id | name | city | country | customer_since | segment | phone |
|---|---|---|---|---|---|---|
| 1 | Harbor Fremont Partners | Boston | USA | 2021-03-15 | Business | 617-555-0142 |
| 2 | Emily Carter | Chicago | USA | 2022-07-01 | Consumer | NULL |
| 3 | Riverside County Office | Riverside | USA | 2020-11-20 | Government | 951-555-0110 |
| 4 | Raj Patel | Leeds | UK | 2023-01-09 | Consumer | 0113 496 0123 |
| 5 | Lakeview Hotel Ltd | Manchester | UK | 2022-04-18 | Business | 0161 496 0456 |
| 6 | Olivia Brooks | Austin | USA | 2024-02-27 | Consumer | NULL |
| 7 | Greene & Shaw LLP | London | UK | 2021-09-05 | Business | 020 7946 0321 |
| 8 | Maple Grove High School | Austin | USA | 2023-08-14 | School | 512-555-0187 |
| 9 | Chloe Evans | Boston | USA | 2025-05-30 | Consumer | 617-555-0199 |
| 10 | Northline Printing Co | Toronto | Canada | 2020-06-12 | Business | 416-555-0133 |
| 11 | Daniel Kim | Seattle | USA | 2024-10-03 | Consumer | NULL |
| 12 | Westbrook Dental Clinic | Chicago | USA | 2022-12-01 | Business | 312-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_id | name | city | country | customer_since | segment | phone |
|---|---|---|---|---|---|---|
| 1 | Harbor Fremont Partners | Boston | USA | 2021-03-15 | Business | 617-555-0142 |
| 2 | Emily Carter | Chicago | USA | 2022-07-01 | Consumer | NULL |
| 3 | Riverside County Office | Riverside | USA | 2020-11-20 | Government | 951-555-0110 |
| 4 | Raj Patel | Leeds | UK | 2023-01-09 | Consumer | 0113 496 0123 |
| 5 | Lakeview Hotel Ltd | Manchester | UK | 2022-04-18 | Business | 0161 496 0456 |
| 6 | Olivia Brooks | Austin | USA | 2024-02-27 | Consumer | NULL |
| 7 | Greene & Shaw LLP | London | UK | 2021-09-05 | Business | 020 7946 0321 |
| 8 | Maple Grove High School | Austin | USA | 2023-08-14 | School | 512-555-0187 |
| 9 | Chloe Evans | Boston | USA | 2025-05-30 | Consumer | 617-555-0199 |
| 10 | Northline Printing Co | Toronto | Canada | 2020-06-12 | Business | 416-555-0133 |
| 11 | Daniel Kim | Seattle | USA | 2024-10-03 | Consumer | NULL |
| 12 | Westbrook Dental Clinic | Chicago | USA | 2022-12-01 | Business | 312-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_id | customer_id | order_date | status | employee_id |
|---|---|---|---|---|
| 1001 | 1 | 2026-01-08 | delivered | 3 |
| 1002 | 4 | 2026-01-12 | delivered | 4 |
| 1003 | 3 | 2026-01-20 | delivered | 3 |
| 1004 | 7 | 2026-02-03 | delivered | 4 |
| 1005 | 2 | 2026-02-11 | cancelled | 8 |
| 1006 | 1 | 2026-02-25 | delivered | 3 |
| 1007 | 10 | 2026-03-04 | delivered | 2 |
| 1008 | 5 | 2026-03-17 | delivered | 4 |
| 1009 | 8 | 2026-03-30 | delivered | 3 |
| 1010 | 6 | 2026-04-07 | delivered | 8 |
| 1011 | 12 | 2026-04-22 | delivered | 4 |
| 1012 | 3 | 2026-05-06 | delivered | 3 |
| 1013 | 9 | 2026-05-19 | cancelled | 8 |
| 1014 | 7 | 2026-06-02 | shipped | 4 |
| 1015 | 1 | 2026-06-10 | shipped | 3 |
| 1016 | 11 | 2026-06-12 | open | NULL |
| 1017 | 4 | 2026-06-13 | open | NULL |
| 1018 | 10 | 2026-06-14 | open | NULL |
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
- Basics: tables, rows, columns: 2 exercises
- SELECT: query columns: 2 exercises
- WHERE: filter rows: 3 exercises
- AND, OR, NOT: 3 exercises
- IN and BETWEEN: 3 exercises
- LIKE: pattern matching: 3 exercises
- NULL and COALESCE: 3 exercises
- ORDER BY and LIMIT: 3 exercises
- DISTINCT: drop duplicates: 2 exercises
- Calculations and column aliases: 3 exercises
- Project: Customer list: 2 exercises
Level 2: Summarizing data
- COUNT: count rows: 3 exercises
- SUM, AVG, MIN, MAX: 3 exercises
- GROUP BY: summarize groups: 3 exercises
- HAVING: filter groups: 3 exercises
- CASE WHEN: conditional logic: 3 exercises
- String functions: 3 exercises
- Dates and times: 3 exercises
- Project: Sales report: 2 exercises
Level 3: Joining tables
- INNER JOIN: joining tables: 3 exercises
- LEFT JOIN: 3 exercises
- Joining multiple tables: 3 exercises
- Self join: 3 exercises
- UNION: 3 exercises
- Subqueries: 3 exercises
- EXISTS and NOT EXISTS: 3 exercises
- Project: Order overview: 2 exercises
Level 4: Changing data and building tables
- INSERT: adding rows: 3 exercises
- UPDATE: changing rows: 3 exercises
- DELETE: removing rows: 3 exercises
- CREATE TABLE: 3 exercises
- ALTER TABLE: 3 exercises
- Primary and foreign keys: 3 exercises
- Views: 3 exercises
- Transactions: 3 exercises
- Project: Inventory: 2 exercises
Level 5: Advanced queries
- WITH (CTE): 3 exercises
- Window functions: ROW_NUMBER, RANK: 3 exercises
- Running totals and shares: 3 exercises
- LAG and LEAD: 3 exercises
- Pivot with CASE WHEN: 3 exercises
- Finding duplicates: 3 exercises
- Project: Customer analysis: 2 exercises
Level 6: Real work and final test
- Order of execution: 3 exercises
- SQL for Excel users: 3 exercises
- MySQL, PostgreSQL, SQL Server: 3 exercises
- Project: Monthly report: 2 exercises
- SQL final test
Bonus: Database design
- Normalization: 3 exercises
- ER diagrams and table design: 3 exercises
Bonus: Performance
- Indexes: 3 exercises
- EXPLAIN: understanding queries: 3 exercises
Bonus: Recursive queries and upserts
- Recursive queries: 3 exercises
- UPSERT: insert or update: 3 exercises
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 tableto 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.