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.
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.
| Page | What it's for | When to open it |
|---|---|---|
| This roadmap | The plan: what each milestone covers and how to check yourself | At the start of each milestone |
| SQL cheat sheet | Learn each idea: short explanation, example, exercise | The "learn" step of every milestone |
| Milestones & Mini-Projects | A dataset and tasks with expected results for each milestone | The "solve" and "check" steps |
| Quick Reference | Look up syntax, functions, and other databases' spellings | Any time you're writing SQL |
| SQL Best Practices | Habits that keep SQL readable, fast, and safe | After Milestone 4, then before every merge |
| SQL: The Complete Guide | Internals and interview questions | When you want the deeper "why" |
Part 1 — Core SQL: Milestones 1–7
In short: everyone does these seven, in order.
| Milestone | You learn | You work on |
|---|---|---|
| 1 | Choosing, sorting, and limiting rows | Library catalogue |
| 2 | Counting, grouping, and summarising | Weather report |
| 3 | Joining tables | Library loans |
| 4 | Creating tables, constraints, changing data | To-do app schema |
| 5 | Subqueries, CTEs, CASE | Customer segments |
| 6 | Window functions | Game leaderboard |
| 7 | Transactions, indexes, query plans | Bank ledger |
For each milestone:
- Learn — read the cheat-sheet sections listed below, and run every example on the practice database.
- Solve — run the milestone's setup in Milestones & Mini-Projects, then write a query for each task.
- Check — compare your result with the expected one. Only then open the solution, and compare the two queries too.
- Commit — save your queries in
milestone-N.sqland 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 = NULLnever match anything? - What's the difference between
LIKE 'The%'andLIKE '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(*)andCOUNT(column)? - When do you use
WHERE, and whenHAVING? - 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 JOINinstead of aJOIN? - How do you find rows in one table with no match in another?
- Why can a join make a
SUMorCOUNTtoo 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 CASCADEdo, and when is it dangerous? - What's your routine before running an
UPDATEon 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 EXISTSsafer thanNOT 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 BYandPARTITION BY? - When do
RANK,DENSE_RANK, andROW_NUMBERgive 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.
| Role | Read next | Final project |
|---|---|---|
| SDET (test engineer) | SQL for SDET — checking what the app saved, test data, data-quality checks, comparing tables, testing migrations | A database test suite that runs in CI |
| SDE (software developer) | SQL Best Practices sections 6–11, then the complete guide on indexes and transactions | A small app with migrations and parameterised queries |
| SRE (reliability engineer) | Isolation & locking, Reading query plans, and the Quick Reference's monitoring one-liners | A 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
| Problem | What 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 join | A join condition is missing or matches more than you expected — count rows after each join. |
| Right numbers, wrong order | Add or fix ORDER BY. |
| Your answer differs from the expected one | Run 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:
| Tool | What it does |
|---|---|
| DBeaver or pgAdmin | Free desktop apps to browse tables and run queries |
psql / sqlite3 | Command-line clients — see the command table |
| Docker | Run 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.