Course map · One concept at a time · Free
SQL TutorialEvery lesson, from SELECT to window functions and beyond
This is the whole DB Quacks SQL tutorial on one page. Each lesson teaches one concept — a few combine several — gives you a task, and checks your query against real data the moment you run it — in your browser, with no signup and nothing to install. The MotherDuck cloud track at the end is the one exception: it needs a free MotherDuck account.
[START LESSON 1]How the lessons work
Every lesson opens with a short story from the duck village, a task, and an editor. You write the SQL, press run, and DuckDB executes it on the spot against the village database. When your result matches the expected one, the level is complete. Stuck? Each lesson has a hint, a preview of the expected output, and a link to the documentation for the feature it teaches.
Lessons build on each other, so start at the top if SQL is new to you. If you already know the basics, jump straight to the concept you need: every SQL lesson works on its own. In the cloud track, some lessons use a share or database you attach or create in an earlier one, so take that track in order.
SQL tutorial (38 lessons)
Chapter 1: Reading a table
- SHOW TABLES in DuckDB — The Great Catalog Mystery
- DESCRIBE a Table in SQL — Schema and Tell
- SQL SELECT * — All Ducks on Deck
- SQL WHERE Clause — Where in the Pond is Carmen San-Duck-o?
- SQL ORDER BY — The Chaos of the Annual Pond Census
- SQL LIMIT — The Overwhelming Data Buffet
Chapter 2: Shaping and summarizing rows
- SQL Calculated Columns — The Great Age Conversion Crisis
- SQL SELECT DISTINCT — Fifty Shades of Duck
- DuckDB USING SAMPLE — The SAMPLE Awakens
- SQL Aggregate Functions — The Great Duck Statistics Quest
- SQL Date Intervals — Duck to the Future: Temporal Mechanics
- SQL GROUP BY — Birds of a Feather GROUP Together
- SQL HAVING — HAVING a Ball with Conditional Counting
Chapter 3: Querying files
- Read a CSV File in DuckDB — The Duck Hunt: CSV Edition
- Read a JSON File in DuckDB — JSON and the Amazing Technicolor Dreamcoat
- Read a Parquet File in DuckDB — Parquet and Recreation
Chapter 4: Joins and CASE WHEN
- SQL INNER JOIN — The Parent Trap: A JOIN Story
- SQL JOIN with WHERE — Pond Bouncers: The WHERE-JOIN Chronicles
- SQL CASE WHEN — CASE Closed: The Duck Detective Story
- SQL LEFT JOIN — No Duck LEFT Behind
- Join CSV and JSON Files in SQL — When Harry Met Sally: A Table-JSON Love Story
- GROUP BY, HAVING and ORDER BY — DuckCon 2024: Executive Dashboard Madness
Chapter 5: UNION, window functions and CTEs
- SQL UNION — UNION Jack and the Quest for Set Operations
- SQL ROW_NUMBER — The ROW_NUMBER Awakens
- SQL LAG and LEAD — Back to the Future: LAG and LEAD
- SQL Running Total with SUM OVER — The Running Man: A SUM OVER Story
- SQL CTE (WITH Clause) — WITH Great Power: The CTE Symphony
- Recursive CTE in SQL — Duck Dynasty: The Recursive Family Saga
Chapter 6: Subqueries, PIVOT, ROLLUP and JSON
- SQL Subquery — Inception: We Need to Go Deeper
- DuckDB SELECT * EXCLUDE — The SELECT-List Wizard of Oz
- SQL PIVOT — The Matrix: PIVOT Reloaded
- SQL UNPIVOT — Transformers: UNPIVOT in Disguise
- SQL ROLLUP — The Lord of the Rings: ROLLUP of Power
- DuckDB JSON Functions — JSON Bourne: The Schema Identity
Chapter 7: Remote files, spatial, full-text search and ASOF JOIN
- Query Remote Files with DuckDB httpfs — Cloud Atlas: The Remote Awakening
- DuckDB Spatial — Finding Nemo: A Spatial Odyssey
- DuckDB Full-Text Search — The Lord of the Strings: Full-Text Search
- DuckDB ASOF JOIN — Endgame - Data Assembly
MotherDuck cloud track (20 lessons)
Chapter 1: Connecting and first queries
- Connect DuckDB to MotherDuck — To Infinity and Be-Pond
- Query a MotherDuck Table — First Contact
- MotherDuck Hybrid Queries — The Bridge Over Troubled Data
Chapter 2: Exploring cloud tables
- DESCRIBE a MotherDuck Table — X Marks the Schema
- Join Local and Cloud Tables — Hot Duck Summer
- Aggregate Cloud Data in MotherDuck — Crunching the Cloud
Chapter 3: Attaching shares
- ATTACH a MotherDuck Share — Open Sesame Data
- Query Several MotherDuck Shares — Roll Call Across Worlds
Chapter 4: Your own database and share
- CREATE DATABASE in MotherDuck — A Room of One's Own
- Copy Data into a MotherDuck Table — Stock the Pond
- CREATE SHARE in MotherDuck — Share and Share Alike
Chapter 5: Remote files from URLs
- DuckDB read_csv from a URL — The CSV Scrolls
- DuckDB read_parquet from a URL — Parquet-ly Cloudy
- Join a Remote CSV with Cloud Tables — The Great Convergence
Chapter 6: DuckLake time travel
- DuckLake Time Travel — Quack to the Future
- Compare DuckLake Snapshots — Spot the Difference
- DuckLake Time Travel with Shares — Past Meets Present Meets Shared
Chapter 7: Scale, EXPLAIN and everything together
- Aggregate 100 Million Rows in MotherDuck — The Hundred-Million Row March
- EXPLAIN a MotherDuck Hybrid Query — Two Engines, One Query
- Combine Local, Cloud and DuckLake Data — Everything, Everywhere, All at Once
After the tutorial
Put the concepts to work on the story-driven SQL challenges, where each case needs several of them at once, or try the weekly challenge. Preparing for a job? The SQL interview questions page maps the classic questions to the lessons above.