SQL tutorial
Ask questions of data: filter, sort, join and summarize tables. 14 short chapters, one idea each, every example runnable in the page.
Who it's for: Analysts, students and developers who need to pull answers out of a relational database.
Prerequisites: None. Queries run against a small bookstore database loaded into your browser.

How this SQL track is organized
Every lesson queries the same small database: a fictional bookstore with five tables (authors, books, customers, orders and order_items). Chapters 1 to 7 cover reading one table: choosing columns, filtering rows, sorting, pattern matching and handling missing values. Chapters 8 and 9 summarize data with aggregate functions and GROUP BY. Chapters 10 to 12 combine tables with joins and subqueries, and the last two change data and define tables of your own.
The examples use SQLite, the database built into phones, browsers and countless applications. The core of the language (SELECT, WHERE, JOIN, GROUP BY) works the same way in PostgreSQL, MySQL and SQL Server; where SQLite differs, the chapter says so. Queries run in your browser with sql.js, and our test suite runs every one with the sqlite3 command-line tool to check the results shown on the page.
All 14 chapters
- 01Get started
- 02SELECT columns
- 03WHERE filters
- 04AND, OR, NOT, IN, BETWEEN
- 05ORDER BY and LIMIT
- 06LIKE patterns
- 07NULL values
- 08COUNT, SUM, AVG, MIN, MAX
- 09GROUP BY and HAVING
- 10INNER JOIN
- 11LEFT JOIN
- 12Subqueries
- 13INSERT, UPDATE, DELETE
- 14CREATE TABLE and constraints
Practice and reference
Final SQL quiz (14 questions)Cheat sheet: sql cheat sheetOfficial SQL documentation