PostgreSQL Exercises
PostgreSQL Exercises (pgexercises) offers free SQL practice in the browser against a real PostgreSQL database built around a simple country club booking system. Around 80 exercises run from basic selects through joins, subqueries, data modification, aggregates and window functions, dates, strings and recursive queries, each with a hint and a full explanation. The quickest way to go from reading SQL to writing it.
About 80
pgexercises · Sept 2026
CC BY-SA 3.0
pgexercises · Sept 2026
Platform
Web Development
Alisdair Owens
10 to 15 hours
Beginner
Free
What it is
PostgreSQL Exercises was created by Alisdair Owens because, as he writes on the site, there was plenty of material to learn about SQL but little that made it easy to learn by doing. It provides a series of questions and explanations built on one simple dataset, designed as a companion to a good book or the PostgreSQL documentation. Everything runs in the browser, so there is nothing to install. Site content is licensed CC BY-SA 3.0.
The dataset models a country club with three tables: members, facilities and bookings. It is small enough to understand in a few minutes and rich enough for genuinely tricky questions.
What the exercises cover
The categories, in order:
- Basic: select, where, order by, limits, simple conditions.
- Joins and subqueries: inner and outer joins, self joins, correlated subqueries.
- Modifying data: insert, update and delete, including inserts based on queries.
- Aggregates: group by, having, and window functions such as rank and running totals.
- Date: working with timestamps, intervals and date functions.
- String: formatting, pattern matching and string functions.
- Recursive: recursive common table expressions for hierarchical data.
In total there are about 80 exercises. Each has a hint and, once you answer, an explanation of the solution and often of alternative approaches.
Why it beats reading a tutorial
SQL is deceptive. The syntax reads like English, which makes it feel understood, and then writing a three table join with a grouped aggregate turns out to be a different skill. Only writing queries closes that gap. Because each answer is checked against the expected result, you get immediate feedback instead of wondering whether your query is right.
How long it takes and how to approach it
- The basic and joins sections take a few hours for most learners.
- Aggregates, especially the window function exercises, are where most self taught developers stall. Budget extra time there; they are worth it, turning painful multi query workarounds into a few lines.
- Do the recursive section last.
Spread the work over one to two weeks, 30 to 60 minutes a day. Try each exercise without the hint first, and read the explanation even when you get it right, because it often shows a cleaner approach.
Who it is for
- Backend and full stack developers whose SQL is limited to what an ORM generates.
- Students preparing for database courses or technical assessments that include SQL.
- Data analysts moving from spreadsheets to databases.
Limitations
- It is PostgreSQL specific in places (date and string functions), though most skills transfer to MySQL and others.
- It does not teach schema design, indexing or performance tuning.
- The interface is simple and has no accounts, so progress is not tracked across devices.
Pair it with
- The PostgreSQL documentation's tutorial and function reference.
- A database design course for schemas and indexes.
Best for: developers who can read SQL but struggle to write non trivial queries, especially joins, aggregates and window functions.
Ready to start?
Opens on Alisdair Owens in a new tab.
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
Follow along
New writing, resources and project ideas land here first.