SQL Exercises and Practice Problems
SQL exercises turn syntax knowledge into the ability to solve a problem without being told which clause to use. In SQL Arena, queries run in the browser and are checked automatically against hidden data.
Updated · SQL Arena team
What you will practice
- Filtering and expressions
- Joining related tables
- Aggregation
- Window functions
- Subqueries and multi-step logic
A practice problem in the trainer
This is how a problem looks in SQL Arena: the task, the editor, the result and the database schema.
Use the challenges and attempts tables. For each challenge, count all attempts as attempts and successful attempts as passed. Keep challenges with at least two attempts. Return title, attempts, and passed, sorted by attempt count descending and then title.
SELECT c.title, COUNT(a.id) AS attempts, COUNT(*) FILTER (WHERE a.passed) AS passed FROM challenges c JOIN attempts a ON a.challenge_id = c.id GROUP BY c.id, c.title HAVING COUNT(a.id) >= 2 ORDER BY attempts DESC, c.title;
| # | title | attempts | passed |
|---|---|---|---|
| 1 | Active Accounts | 3 | 2 |
| 2 | Daily Revenue | 3 | 2 |
| 3 | Customer Rank | 2 | 1 |
Use the challenges and attempts tables. For each challenge, count all attempts as attempts and successful attempts as passed. Keep challenges with at least two attempts. Return title, attempts, and passed, sorted by attempt count descending and then title.
SELECT c.title, COUNT(a.id) AS attempts, COUNT(*) FILTER (WHERE a.passed) AS passed FROM challenges c JOIN attempts a ON a.challenge_id = c.id GROUP BY c.id, c.title HAVING COUNT(a.id) >= 2 ORDER BY attempts DESC, c.title;
Step-by-step solution
attempts.challenge_id points to challenges.id, so the JOIN creates one row for every recorded attempt together with its challenge information. If a challenge has three attempts, it appears three times before aggregation.
COUNT(a.id) counts all attempt rows. PostgreSQL's FILTER syntax lets the second aggregate count only rows where a.passed is true. GROUP BY then creates one result row per challenge, and HAVING removes groups with fewer than two attempts.
The final ORDER BY uses two keys. attempt count is sorted descending, and the title resolves ties. An explicit ordering matters in SQL practice because without ORDER BY the database does not guarantee that repeated executions will return rows in the same sequence.
SELECT c.title, COUNT(a.id) AS attempts, COUNT(*) FILTER (WHERE a.passed) AS passed FROM challenges c JOIN attempts a ON a.challenge_id = c.id GROUP BY c.id, c.title HAVING COUNT(a.id) >= 2 ORDER BY attempts DESC, c.title;
| title | attempts | passed |
|---|---|---|
| Active Accounts | 3 | 2 |
| Daily Revenue | 3 | 2 |
| Customer Rank | 2 | 1 |
Common SQL exercise mistakes
Overfitting to visible data
An incorrect query can accidentally match a small sample. Hidden-data checks expose assumptions about duplicates, extra rows, missing values, and other cases that were not visible while you wrote the solution.
Reading the answer too early
SQL practice problems are most useful when you first choose an approach yourself. If you are stuck, a targeted hint or explanation preserves more of the learning process than copying the complete solution.
Judging difficulty by query length
A difficult SQL problem can have a short final query. The hard part may be choosing the correct grain, understanding the relationship between tables, or handling an edge case.
Practice problems on this topic
All practice problemsSQL Arena contains 1,192 auto-checked SQL exercises, each with its own tables. Solutions are evaluated on hidden data rather than by comparing your query text with a template. You can practice PostgreSQL, MySQL, ClickHouse, and BigQuery in separate browser sandboxes. The free tier includes 292 problems, mostly Easy, across all four dialects. The available exercise set covers basic SQL exercises as well as Medium, Hard, and Expert problems. Examples include event distribution by hour of day in ClickHouse, row counts by status code, average latency per service, minimum and maximum latency, paid-event filtering, platform geography, user activity timelines, and session endings. When you need help, the AI mentor can provide hints and explain errors; 10 uses are available free in total. Interview mode removes hints, uses a server-side timer, and produces a report after the session, with one free run per day.
- EasyfreeEvent distribution by hour of day (ClickHouse)clickhouse
- EasyfreeRow counts by status code (ClickHouse)clickhouse
- EasyfreeAverage latency per serviceclickhouse
- EasyfreeMin and max latency per serviceclickhouse
- MediumPremiumNothing but Paid Eventsbigquery
- HardPremiumEach Platform’s City Footprintbigquery
- ExpertPremiumEach User’s Activity Timelinebigquery
- MediumPremiumThe End of Each Sessionbigquery
Reference on this topic
In-depth articles with syntax and examples in the SQL Arena reference.
Frequently asked questions
Where can I practice SQL exercises online?
Use an environment where you can run real queries and receive automatic feedback. SQL Arena provides browser-based PostgreSQL, MySQL, ClickHouse, and BigQuery sandboxes with task-specific tables.
What SQL practice problems should beginners solve?
Start with SELECT, WHERE, sorting, expressions, and simple aggregation. Once those feel routine, add joins and problems that require several operations in the same query.
How are SQL exercises checked?
The query result is compared with the expected result on hidden data. This checks whether your logic generalizes beyond the rows you could see while solving the exercise.
Are MySQL practice questions available?
Yes. SQL Arena has a separate MySQL sandbox, along with PostgreSQL, ClickHouse, and BigQuery. The exercise catalog can therefore be used to practice different SQL dialects in the browser.
Solve a SQL problem yourself
Open a task, inspect its tables, write the query, and let the checker test your logic on hidden data. You can begin with the free exercise set without adding a card.
Start SQL PracticeMore practice from CodeRang
- Python ArenaPython Arena has 1300+ Python 3.12 problems covering functions, classes, async code and technical interview tasks.1300+ tasks · Python 3.12
- Playwright ArenaPlaywright Arena has 30 JavaScript and E2E problems where you write a test and immediately see what it did in the browser.30 tasks · JavaScript / E2E