Tutorials
Guided paths through the reference, in the order worth learning them. Every step links to a full page with runnable examples — nothing here is new content, just a map through what already exists.
SQL fundamentals
Start here if WHERE, GROUP BY, and JOIN are still a little shaky. Each step builds on the last.
- 1NULL handling
The three-valued logic that shapes everything downstream.
- 2WHERE
Filtering rows before anything else happens.
- 3DISTINCT
Removing duplicates — and why it applies to the whole row.
- 4ORDER BY
Making result order deterministic and intentional.
- 5GROUP BY
Collapsing rows into groups.
- 6HAVING
Filtering groups, after they’re formed.
- 7CASE
Branching logic inside a query.
- 8INNER JOIN
Combining rows that match in both tables.
- 9LEFT JOIN
Keeping every row from one side, matched or not.
Window functions
For once WHERE/GROUP BY/JOIN feel natural. Window functions unlock a whole class of "rank within a group" and "running total" problems.
- 1The complete guide to window functionsGuide
Start with the narrative — OVER(), PARTITION BY, and how ranking, running totals, and frames all fit together.
- 2ROW_NUMBER
One row per group, no duplicates — the base for top-N-per-group.
- 3RANK / DENSE_RANK
Ranking with ties — two different tie-breaking rules.
- 4Running total
A windowed SUM that keeps row-level detail.
- 5LAG / LEAD
Comparing a row to the one before or after it, no self-join.
- 6Window frames
Controlling exactly which rows a window aggregate sees.
Writing and protecting data
Everything above reads data. This is how it changes — safely.
- 1INSERT
Single row, multi-row, and INSERT … SELECT.
- 2UPDATE
Changing existing rows — and the WHERE clause that stops it from changing every row.
- 3DELETE
Removing rows, and how it differs from TRUNCATE.
- 4BEGIN, COMMIT, ROLLBACK
Grouping statements so they succeed or fail together.
- 5Isolation levels
What one transaction can see of another running at the same time.
Diagnosing a query that’s wrong
The query runs, but the result is wrong, or a rule you swore was true just broke. Start with the symptom that matches.
- 1Why your query returns the wrong number of rowsGuide
A join multiplying rows, or a WHERE silently undoing a LEFT JOIN.
- 2NULL in SQL: the complete guideGuide
Why a query that looks right returns nothing, or a comparison you expected to fail just vanished.
- 3EXISTS and IN
The NOT IN + NULL trap that returns zero rows with no error.
- 4Type coercion
Why a comparison or sort gives a different answer than expected.
- 5The order SQL actually runs inGuide
Why WHERE can’t see a SELECT alias, and other order-of-execution errors.
- 6Query Doctor
Paste the broken query and its error — get the root cause and a fix.
Performance basics
Once queries are correct, make them fast — and prove it.
Prefer to look something up directly? Open the cheat sheet or browse the full reference.