SQL

From your first SELECT to window functions and interview problems. Free, step by step: every lesson is complete, with an animation, a worked example and exercises with answers.

Unit 0: Start here: databases, tables and SQL

Know what a database is, what a table, a row and a key are, and the six practice tables you will use in every lesson.

Unit 1: Reading data: SELECT, WHERE and sorting

Pick the columns you want, keep only the rows you want, sort them, and handle the missing values that trip everyone up.

Unit 2: Summarising data: aggregates, GROUP BY and HAVING

Turn many rows into answers — totals, averages, counts per group — and know exactly which rows each number is built from.

Unit 3: Joins: combining tables

Put rows from two or more tables side by side, keep or drop the rows that have no match on purpose, and spot the joins that quietly double your totals.

Unit 4: Subqueries, CTEs and set operations

Use the result of one query inside another, break hard questions into named steps with WITH, walk trees with recursion, and stack results with UNION.

Unit 5: Window functions: ranking, running totals and comparing rows

Calculate across related rows — rank them, compare each with the one before, keep running totals — without losing the individual rows the way GROUP BY does.

Unit 6: Building tables and changing data

Create tables with the right rules, add, change and remove rows safely, group changes into transactions, and design tables that don't contradict themselves.

Unit 7: Performance: indexes and query plans

Know why a query is slow, read the plan the database chose, and write queries and indexes that let it find rows without reading the whole table.

Unit 8: SQL interview problems, from easy to hard

Solve the classic SQL interview questions from a blank page, explain your approach while you write, and name the edge cases before the interviewer does.