Write 20 SQL Queries Against a Sample Database
Part of the SQL Roadmap
In short
Reading about SQL won't make you fluent. Twenty real queries on a real database will. This project is your net practice before the match.
Practise the basics by writing twenty real queries against a sample database, each answering a plain-English question with SELECT, WHERE, ORDER BY and LIMIT.

Think of it like this
Twenty balls in the nets
A batter doesn't learn the cover drive from videos. They face ball after ball in the nets, starting slow and getting faster. Twenty queries, from easy to tricky, is your net session: each one grooves a pattern you'll use at work.
Watch it happen
The twenty-query ladder
1/6Load a free sample database like Chinook or Northwind into SQLite or PostgreSQL.
The big ideas
What you need to know
Question first, then SQL
Write each question in plain English above its query. That's how real requests arrive.
Increase difficulty
Start easy so you build speed, then push into joins, CTEs and windows.
Sanity-check answers
For each result, ask: does this number make sense? Check row counts after joins.
Make it portfolio-ready
A clean README with questions, queries and findings shows employers you can actually write SQL.
See it in code
Walk through the code
1-- Q17: Top-selling genre in each country (Chinook)2WITH genre_sales AS (3 SELECT c.country, g.name AS genre, SUM(il.unit_price * il.quantity) AS sales4 FROM invoice_line il5 JOIN invoice i ON i.invoice_id = il.invoice_id6 JOIN customer c ON c.customer_id = i.customer_id7 JOIN track t ON t.track_id = il.track_id8 JOIN genre g ON g.genre_id = t.genre_id9 GROUP BY c.country, g.name10)11SELECT country, genre, sales12FROM (13 SELECT *, RANK() OVER (PARTITION BY country ORDER BY sales DESC) AS rnk14 FROM genre_sales15) ranked16WHERE rnk = 1;1/3Join four tables and total sales per country and genre.
A starter for one of the harder queries. Table and column names follow one common Chinook version, so check your copy's schema.
Save yourself the pain
Common mistakes
Oops
Copying answers from a blog without running them.
Do this instead
Write each query yourself first, then compare. Struggling is where the learning happens.
Oops
Saving queries with no question or explanation.
Do this instead
Above each query, write the business question and one line on what the result shows.
Your mission
First five queries
Quick check
After joining invoices to invoice lines, your total revenue looks much higher than expected. What's the likely cause?
Go deeper
- 1Write the business question as a comment above each query.
- 2Mix easy lookups with trickier filters, sorting and calculated columns.
- 3Save the queries in a .sql file in a GitHub repo as the start of your portfolio.
Also part of these roadmaps
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.