SQL Practice Online: Problems With Real Answers
· 7 min read
The best SQL practice online is writing real queries against a small, realistic set of related tables, checking each result yourself, and moving from single-table filters to joins and groups. Reading tutorials helps, but you only learn SQL by typing queries, getting them wrong and working out why. Start with a query you can verify at a glance:
SELECT supplier_name, country
FROM suppliers
ORDER BY supplier_name;Below is what makes practice actually useful, six SQL practice problems on two tables (easy to harder, with solutions and real outputs), how to check an answer when nobody gives you one, and the kind of wrong answer that looks right.
What good SQL practice looks like
Not all SQL exercises are equally useful. Good practice has a few things in common:
- Several related tables. Real questions need joins. One flat table teaches syntax, but not how to pick a join key or notice duplicated rows.
- Business questions, not syntax drills. "Which suppliers deliver late most often?" is better practice than "write a query using HAVING", because working out which clause you need is the skill.
- Messy details. Statuses that should be excluded, missing values, ties. These are where real queries go wrong.
- A way to check the result. Either an automatic check against the right answer, or data small enough that you can verify it by hand.
- Feedback on why, not just right or wrong. Seeing the correct query teaches less than understanding what was wrong with yours.
If you are practising for a data analyst job, add one more: practise reviewing queries, not only writing them. A lot of analyst work now means checking SQL that someone else, or an AI assistant, wrote. Practisheet is built around this: you practise on one fictional company's data, and some tasks hand you an AI assistant's query to audit and fix.
You do not need to install a database server to start. DuckDB and SQLite both run as a single program on your laptop, and many practice sites run SQL right in the browser.
Six SQL practice problems
All six use these two tables. Try each one before you scroll to the solutions.
| supplier_id | supplier_name | country |
|---|---|---|
| 1 | Northwind Paper | UK |
| 2 | Clearwave Chemicals | Germany |
| 3 | Roastery Direct | UK |
| 4 | Pinecrest Plastics | Poland |
| delivery_id | supplier_id | delivered_on | boxes | days_late |
|---|---|---|---|---|
| 1 | 1 | 2025-06-02 | 40 | 0 |
| 2 | 2 | 2025-06-03 | 12 | 2 |
| 3 | 1 | 2025-06-10 | 35 | 1 |
| 4 | 3 | 2025-06-11 | 8 | 0 |
| 5 | 2 | 2025-06-17 | 15 | 0 |
| 6 | 1 | 2025-06-24 | 50 | 3 |
| 7 | 3 | 2025-06-25 | 6 | 0 |
Easy
- List the names of the suppliers based in the UK, A to Z.
- How many deliveries arrived late?
Medium
- Total boxes delivered per supplier_id, largest first.
- For every late delivery, show the supplier's name, the date and the number of boxes, earliest first.
Harder
- Number of deliveries per supplier name, including suppliers with none.
- Average days late per supplier, but only for suppliers whose average is above 0.
Solutions
1. Filter one table
SELECT supplier_name
FROM suppliers
WHERE country = 'UK'
ORDER BY supplier_name;| supplier_name |
|---|
| Northwind Paper |
| Roastery Direct |
Text values go in single quotes and must match exactly. More in the SQL WHERE clause.
2. Count with a condition
SELECT COUNT(*) AS late_deliveries
FROM deliveries
WHERE days_late > 0;| late_deliveries |
|---|
| 3 |
3. Group and sort
SELECT supplier_id, SUM(boxes) AS boxes
FROM deliveries
GROUP BY supplier_id
ORDER BY boxes DESC;| supplier_id | boxes |
|---|---|
| 1 | 125 |
| 2 | 27 |
| 3 | 14 |
Supplier 4 is missing because it has no deliveries. That is correct for this question, and it sets up problem 5.
4. Join two tables
SELECT s.supplier_name, d.delivered_on, d.boxes
FROM deliveries AS d
JOIN suppliers AS s ON s.supplier_id = d.supplier_id
WHERE d.days_late > 0
ORDER BY d.delivered_on;| supplier_name | delivered_on | boxes |
|---|---|---|
| Clearwave Chemicals | 2025-06-03 | 12 |
| Northwind Paper | 2025-06-10 | 35 |
| Northwind Paper | 2025-06-24 | 50 |
Three rows, matching the count from problem 2. Cross-checking answers like this is a good habit.
5. Keep rows with no match
SELECT s.supplier_name, COUNT(d.delivery_id) AS deliveries
FROM suppliers AS s
LEFT JOIN deliveries AS d ON d.supplier_id = s.supplier_id
GROUP BY s.supplier_name
ORDER BY deliveries DESC, s.supplier_name;| supplier_name | deliveries |
|---|---|
| Northwind Paper | 3 |
| Clearwave Chemicals | 2 |
| Roastery Direct | 2 |
| Pinecrest Plastics | 0 |
Two details make this work: LEFT JOIN keeps Pinecrest Plastics, and COUNT(d.delivery_id) gives it 0. COUNT(*) would give it 1, because the unmatched row still exists. See SQL LEFT JOIN explained.
6. Filter groups
SELECT s.supplier_name, ROUND(AVG(d.days_late), 2) AS avg_days_late
FROM suppliers AS s
JOIN deliveries AS d ON d.supplier_id = s.supplier_id
GROUP BY s.supplier_name
HAVING AVG(d.days_late) > 0
ORDER BY avg_days_late DESC;| supplier_name | avg_days_late |
|---|---|
| Northwind Paper | 1.33 |
| Clearwave Chemicals | 1 |
The condition is on an average, so it goes in HAVING, not WHERE. Why is explained in HAVING vs WHERE.
How to check your own answer
When there is no answer key, check the result like an analyst would:
- Count the rows you expect before you run the query. Problem 5 should have one row per supplier: 4.
- Check one row by hand. Northwind Paper's boxes: 40 + 35 + 50 = 125.
- Cross-check two queries. Problem 2 and problem 4 should agree on the number of late deliveries.
- Look for impossible values. A negative count, a date outside the data, an average larger than the maximum.
For more SQL practice problems at interview level, try SQL interview questions for data analysts.
Common mistakes
A join on the wrong key (the AI mistake to watch for)
Ask an AI assistant to write problem 4 and occasionally it joins on the wrong column, especially when two ID columns look alike:
SELECT s.supplier_name, d.delivered_on, d.boxes
FROM deliveries AS d
JOIN suppliers AS s ON s.supplier_id = d.delivery_id
WHERE d.days_late > 0
ORDER BY d.delivered_on;| supplier_name | delivered_on | boxes |
|---|---|---|
| Clearwave Chemicals | 2025-06-03 | 12 |
| Roastery Direct | 2025-06-10 | 35 |
It runs and the output looks believable. But it matched supplier IDs to delivery IDs. Delivery 3 was from Northwind Paper, not Roastery Direct, and delivery 6 disappeared because there is no supplier 6. Only one of the two rows is right, and only by coincidence.
How to spot it: read every ON line and say it out loud: "supplier's id equals the delivery's supplier id". Then compare the row count with a simpler query (problem 2 says there are 3 late deliveries, not 2).
Checking only that the query runs
A query that runs is not a query that is right. Most practice mistakes produce plausible output. Use the checks above every time.
Copying the solution instead of fixing your own
If your attempt was wrong, find the exact line that made it wrong before reading the solution. That is the part you will remember.
FAQ
Where can I practise SQL online for free?
Any environment where you can run queries against sample tables works: a browser-based SQL editor, or DuckDB or SQLite on your own laptop with a small dataset. Choose one with several related tables and a way to check your results.
How can I practise SQL every day?
Pick one business question a day and answer it with a query, then check it. Fifteen focused minutes on one problem is worth more than an hour of reading.
What SQL exercises should a beginner start with?
Single-table SELECT and WHERE, then COUNT and GROUP BY, then one join between two tables. Problems 1 to 4 above follow that order.
Are SQL practice problems enough to get a job?
They build the skill. For interviews, also practise explaining your query, and reviewing someone else's query for mistakes, since both come up often.
Practise this on a realistic dataset
Solve it yourself on one company's data, with instant feedback that points at what's wrong without giving away the answer.
Try “Your first query” →