TetSharing

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.

Start with chapter 1 →

A laptop showing an analytics dashboard with charts
Photo: kmuza on Unsplash

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

  1. 01Get started
  2. 02SELECT columns
  3. 03WHERE filters
  4. 04AND, OR, NOT, IN, BETWEEN
  5. 05ORDER BY and LIMIT
  6. 06LIKE patterns
  7. 07NULL values
  8. 08COUNT, SUM, AVG, MIN, MAX
  9. 09GROUP BY and HAVING
  10. 10INNER JOIN
  11. 11LEFT JOIN
  12. 12Subqueries
  13. 13INSERT, UPDATE, DELETE
  14. 14CREATE TABLE and constraints

Practice and reference

Final SQL quiz (14 questions)Cheat sheet: sql cheat sheetOfficial SQL documentation