Module · 4 lessons

Combining Tables with Joins

Bring data spread across many tables back together with inner, outer, self, and cross joins, plus set operators.

At a glance

Level
Intermediate
Lessons
4 lessons
Time to complete
1–2 weeks
Cost
Free forever · no sign-up

Welcome to Combining Tables with Joins — the module where your SQL stops living inside a single table and starts answering the questions that real databases are actually built to answer. Up to now you have queried one table at a time. But production databases almost never keep everything in one place. Customer details sit in one table, their purchases in another, the tracks they bought in a third. To turn that into a useful report, you have to bring the pieces back together.

Data for this module

Database: chinook.db — a digital music store (SQLite).

Open it in any SQLite client — DB Browser for SQLite, the sqlite3 CLI, or Python’s sqlite3. Each lesson lists the specific tables it uses.

Throughout this module you will work with the Chinook database, a realistic model of a digital music store with tables for customers, invoices, tracks, albums, artists, employees, and more. Your job is to connect these tables the way a working analyst does: list every customer’s purchases, count tracks per genre, match each employee to their manager, find every invoice from a given year, and combine results that live in separate tables entirely.

You will start with the inner join, the workhorse that matches rows across tables on a shared column. From there you will layer joins together with WHERE, GROUP BY, and ORDER BY, join three or more tables at once, and then reach for the less common joins — self joins, left and right outer joins, full joins, and cross joins — that handle the trickier real-world cases. Finally, you will learn set operators (UNION, INTERSECT, and EXCEPT) for stacking and comparing entire query results.

No new tools are required — just the SQL you already know, plus a willingness to think about how tables relate. Start with Lesson 1, where you will write your first inner join and learn exactly how SQL stitches two tables into one.

Lessons in this module

Achievement

Complete all 4 lessons to finish the Combining Tables with Joins module.

Start module