Interactive course · 28 lessons · ~9 hours

SQL, explained by how the engine runs it.

Most SQL tutorials teach you clauses in the order you type them. That is why WHERE rejecting your alias feels arbitrary, why NOT IN silently returns nothing, and why your index is ignored. This course teaches the order the database actually executes in — and then everything else follows.

0 of 28 lessons complete0%

The one idea this course is built on

You write SQL top to bottom. The database does not read it that way. Learn this order and a surprising number of "SQL is weird" moments stop being weird.

What you WRITE SELECT city, SUM(amount) AS total FROM orders o JOIN customers c ON ... WHERE o.status = 'PAID' GROUP BY city HAVING SUM(amount) > 1000 ORDER BY total DESC What the engine RUNS 1. FROM + JOIN build the working set 2. WHERE throw rows away 3. GROUP BY collapse into groups 4. HAVING throw GROUPS away 5. SELECT compute the columns ← aliases born HERE 6. ORDER BY sort 7. LIMIT cut Three mysteries this immediately solves · "Unknown column 'total' in WHERE" — WHERE runs at step 2; the alias is not created until step 5. · ORDER BY can use that alias — it runs at step 6, after SELECT. Same query, different rule. · WHERE filters rows, HAVING filters groups. They are not interchangeable; they run either side of GROUP BY. And this is only the LOGICAL order The optimiser is free to execute differently — pushing filters into an index scan, reordering joins, streaming a sort — as long as the ANSWER matches this model. Reading the real plan is lesson 27.
FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT. Lesson 02 unpacks every step; the rest of the course hangs off it.

Pick a path

~2 hours

I need to query a database at work

Lessons 02, 04, 05, 07, 09, 12, 14. You will handle most day-to-day reporting questions confidently.

~3 hours

I have a data interview

Lessons 02, 09, 12, 14, 15, 22, 25, 26, 27 — then the project. Joins, windows and indexes are most of what is asked.

~2 hours

My query is slow

Lessons 26, 27, then 17 (sargability) and 12 (subquery rewrites). Learn to read a plan before changing anything.

~2 hours

I'm designing a schema

Lessons 20, 21, 22, 23, 25. Types, constraints, normal forms and safe migrations.

Ships with a real project

🛠 A 5-table retail database and 30 graded challenges

4,007 rows across customers, products, orders, order_items and returns — deliberately imperfect: NULL cities, guest orders with no customer, negative quantities, duplicate people, orders with no items, refunds bigger than the order.

Then 30 questions from "list customers in Kerala" to cohort retention and a Pareto analysis. Every solution is executed against the database, so the answers are verified, not hopeful. Runs in SQLite with zero installation.

Open the project →

The curriculum

Dialect

Lessons teach standard SQL and call out where PostgreSQL, MySQL and SQLite differ — because you will meet all three. The project runs on SQLite so you need nothing installed, and the scripts note the Postgres/MySQL variants inline.

Keyboard

/ search · ← → move between lessons · progress is saved in your browser only.