Course 08 · Data

SQL
Data that outlives the page.

The language every database answers to. One door factory, twenty-two lessons, and a real SQLite engine running your queries in the page.

22Lessons
≈ 5hReading
22Playable now
QueriesJoinsAggregatesSchemaIndexesTransactions

0 of 22 lessons finished — nothing yet

The syllabus

22 lessons,
in the order they build on each other.

Start lesson one ↗
01

What a database is for

Tables, rows and columns — and what a database gives you that a JSON file cannot.

≈ 10 min
02

SELECT

Asking for columns, renaming them, doing arithmetic, and reading the result as a table.

≈ 11 min
03

WHERE

Comparisons, AND and OR and the brackets between them, BETWEEN, IN and LIKE.

≈ 12 min
04

NULL

The value that is not a value: three-valued logic, IS NULL, and the bug it causes in every codebase.

≈ 11 min
05

ORDER BY and LIMIT

Sorting on columns and expressions, ties, NULL placement, paging and why the order is otherwise undefined.

≈ 10 min
06

Counting and summing

COUNT, SUM, AVG, MIN, MAX, DISTINCT — and the difference between COUNT(*) and COUNT(column).

≈ 12 min
07

GROUP BY and HAVING

One row per group, the bare-column rule, filtering before and after grouping.

≈ 13 min
08

Joining tables

Foreign keys in practice: INNER JOIN, the ON clause, aliases, and joining three tables.

≈ 14 min
09

LEFT JOIN and the rows that are missing

Keeping rows that have no match, finding the ones that have none, and the WHERE that silently undoes it.

≈ 13 min
10

Self joins and cross joins

A table joined to itself, every combination on purpose, and the accidental Cartesian product.

≈ 11 min
11

Subqueries

A query inside a query: scalar, IN, EXISTS, correlated — and which of them the planner likes.

≈ 13 min
12

Common table expressions

WITH: naming the steps so a long query reads top to bottom, and recursion for trees.

≈ 12 min
13

Window functions

Keeping every row and still seeing the whole: OVER, PARTITION BY, ranks, running totals, LAG.

≈ 14 min
14

Writing data

INSERT, UPDATE, DELETE, RETURNING, upserts — and the WHERE you must not forget.

≈ 12 min
15

Designing a table

CREATE TABLE, types, NOT NULL, DEFAULT and CHECK: making bad data impossible to store.

≈ 13 min
16

Keys and relationships

Primary keys, foreign keys, one-to-many, many-to-many, and what ON DELETE decides.

≈ 13 min
17

Normalisation, and when to stop

One fact in one place, the anomalies it prevents, and the copies worth keeping anyway.

≈ 12 min
18

Indexes

What a B-tree can do, what an index costs on write, and reading the query plan.

≈ 14 min
19

Transactions

All or nothing: BEGIN, COMMIT, ROLLBACK, what ACID promises and what isolation does not.

≈ 12 min
20

Text, dates and JSON

String functions, storing time so it sorts, and the JSON column that saves you from a table.

≈ 12 min
21

SQL from an application

Parameters, injection, pools, migrations and the N+1 query that quietly ruins a page.

≈ 13 min
22

Practice: the whole floor

Eight questions a business actually asks, answered with everything the course has taught.

≈ 15 min