Learn SQL from zero
Short lessons with examples you can run and edit, then practice that is checked on hidden data. Free, and no account needed.
Stage 1: Basics
Read data out of a table: pick columns, filter rows, sort them, and deal with missing values.
- Your first SELECT — 4 min
- Filtering rows with WHERE — 5 min
- Sorting with ORDER BY and LIMIT — 5 min
- Removing duplicates with DISTINCT — 3 min
- Missing values: NULL — 5 min
Stage 2: Filtering
Combine conditions, match lists, ranges and patterns, and turn values into labels with CASE.
- AND, OR and NOT — 5 min
- Lists and ranges: IN and BETWEEN — 4 min
- Text patterns with LIKE — 4 min
- Labels with CASE — 5 min
Stage 3: Aggregation
Summarise many rows into one: counts, totals and averages, per group, and filter the groups.
- Counting and totals — 5 min
- Groups with GROUP BY — 6 min
- Filtering groups with HAVING — 5 min
- Counting distinct values — 4 min
Stage 4: Joins
Combine tables through their keys: inner and left joins, a table joined to itself, and joins with aggregates.
- Combining tables with JOIN — 6 min
- Keeping unmatched rows: LEFT JOIN — 6 min
- Joining a table to itself — 6 min
- Joins with aggregates — 6 min
Coming soon
- Subqueries & CTEs: Subqueries in WHERE, Correlated subqueries, WITH (CTEs)
- Window functions: ROW_NUMBER and RANK, LAG and LEAD, Running totals
- Boss level: Recursive CTEs, Gaps and islands