Skip to main content

SQL Learning Path: Start Here

In short: you learn SQL in 7 milestones. Each one has a small dataset and a set of tasks with the expected answers, so you always know whether you're right. Then you apply SQL to your role.

How to use this page

Read this page once to see the plan. Then, for each milestone, follow the same four steps: learn → solve → check → commit. Come back here whenever you're unsure what to do next.

The pages in this learning path​

In short: each page has one job, so nothing is explained twice.

PageWhat it's forWhen to open it
This roadmapThe plan: what each milestone covers and how to check yourselfAt the start of each milestone
SQL cheat sheetLearn each idea: short explanation, example, exerciseThe "learn" step of every milestone
Milestones & Mini-ProjectsA dataset and tasks with expected results for each milestoneThe "solve" and "check" steps
Quick ReferenceLook up syntax, functions, and other databases' spellingsAny time you're writing SQL
SQL Best PracticesHabits that keep SQL readable, fast, and safeAfter Milestone 4, then before every merge
SQL: The Complete GuideInternals and interview questionsWhen you want the deeper "why"

Part 1 — Core SQL: Milestones 1–7​

In short: everyone does these seven, in order.

MilestoneYou learnYou work on
1Choosing, sorting, and limiting rowsLibrary catalogue
2Counting, grouping, and summarisingWeather report
3Joining tablesLibrary loans
4Creating tables, constraints, changing dataTo-do app schema
5Subqueries, CTEs, CASECustomer segments
6Window functionsGame leaderboard
7Transactions, indexes, query plansBank ledger

For each milestone:

  1. Learn — read the cheat-sheet sections listed below, and run every example on the practice database.
  2. Solve — run the milestone's setup in Milestones & Mini-Projects, then write a query for each task.
  3. Check — compare your result with the expected one. Only then open the solution, and compare the two queries too.
  4. Commit — save your queries in milestone-N.sql and commit:
git add milestone-1.sql
git commit -m "Milestone 1: library catalogue, 8/8 tasks correct"

Milestone 1: Choosing rows​

Learn: What SQL is · Choosing rows · Sorting & limiting · Text, numbers & NULL

Work on: Library catalogue

Check yourself:

  • Why does WHERE email = NULL never match anything?
  • What's the difference between LIKE 'The%' and LIKE 'The %'?
  • Why can't you rely on row order without ORDER BY?

Milestone 2: Counting & grouping​

Learn: Counting & grouping · Quick Reference: Aggregates, Clause order

Work on: Weather report

Check yourself:

  • What's the difference between COUNT(*) and COUNT(column)?
  • When do you use WHERE, and when HAVING?
  • Why must every selected column be grouped or aggregated?

Milestone 3: Joining tables​

Learn: Joining tables · Quick Reference: Joins

Work on: Library loans

Check yourself:

  • When do you need a LEFT JOIN instead of a JOIN?
  • How do you find rows in one table with no match in another?
  • Why can a join make a SUM or COUNT too big?

Milestone 4: Building tables & changing data​

Learn: Changing data · Creating tables · Insert or update (upsert)

Work on: To-do app schema

Then read: SQL Best Practices, sections 1–5 and 8–9.

Check yourself:

  • What does each constraint type protect against?
  • What does ON DELETE CASCADE do, and when is it dangerous?
  • What's your routine before running an UPDATE on real data?

Milestone 5: Subqueries, CTEs & CASE​

Learn: Subqueries · CTEs · CASE · Combining results · Views

Work on: Customer segments

Check yourself:

  • When is a CTE clearer than a subquery?
  • Why is NOT EXISTS safer than NOT IN?
  • How do you count several conditions in one pass?

Milestone 6: Window functions​

Learn: Window functions · Dates & times · Quick Reference: Window functions

Work on: Game leaderboard

Check yourself:

  • What's the difference between GROUP BY and PARTITION BY?
  • When do RANK, DENSE_RANK, and ROW_NUMBER give different answers?
  • How do you get the top row per group?

Milestone 7: Transactions & performance​

Learn: Indexes · Transactions · Reading query plans · Isolation & locking · Recursive queries

Work on: Bank ledger

Check yourself:

  • What do the four letters of ACID promise?
  • Which columns would you index first, and what does each index cost?
  • How do you spot a full-table scan in a plan?

Part 2 — Your role track​

In short: SQL is used differently by each role. Pick yours.

RoleRead nextFinal project
SDET (test engineer)SQL for SDET — checking what the app saved, test data, data-quality checks, comparing tables, testing migrationsA database test suite that runs in CI
SDE (software developer)SQL Best Practices sections 6–11, then the complete guide on indexes and transactionsA small app with migrations and parameterised queries
SRE (reliability engineer)Isolation & locking, Reading query plans, and the Quick Reference's monitoring one-linersA runbook for "the database is slow": find the query, read its plan, fix it

Also finish the cheat sheet's Part 3: JSON columns, Designing tables, and SQL from code.

How you know you're ready to move on​

After Milestone 7:

  • Every task in all seven milestones gives the expected result.
  • You can write a three-table join with grouping without looking anything up.
  • You can explain a query plan's main line to someone else.
  • Your git history shows steady progress.

If you get stuck​

ProblemWhat to do
"column … does not exist"Check the clause order: WHERE can't use a SELECT alias. Also check spelling and table aliases.
"must appear in the GROUP BY clause"Every selected column must be grouped or inside COUNT/SUM/….
Too many rows after a joinA join condition is missing or matches more than you expected — count rows after each join.
Right numbers, wrong orderAdd or fix ORDER BY.
Your answer differs from the expected oneRun the setup again on a fresh database — earlier experiments may have changed the data.

Start now​

Install PostgreSQL (or use SQLite, already on macOS and most Linux), create a database, and load the practice data from the cheat sheet.

createdb shop                       # PostgreSQL: create a database
psql shop # open it, then paste the practice setup
# or, with SQLite:
sqlite3 shop.db # creates the file on first use

Helpful tools:

ToolWhat it does
DBeaver or pgAdminFree desktop apps to browse tables and run queries
psql / sqlite3Command-line clients — see the command table
DockerRun PostgreSQL without installing it: docker run -e POSTGRES_PASSWORD=pw -p 5432:5432 postgres

Good books to read alongside: Learning SQL (Alan Beaulieu) to build foundations, and SQL Performance Explained (Markus Winand, also free online as "Use The Index, Luke") for indexes and speed.