We're making some improvements. Some features may be temporarily unavailable.
intermediate30 min

JOINs & Relationships

Combine data across multiple tables with INNER JOIN, LEFT JOIN, and more

Why JOINs Matter

Real databases rarely use a single table. Data is split across related tables to avoid duplication. JOINs let you combine data from multiple tables in a single query.

Setting Up Related Tables

Output
Run your code to see output here

INNER JOIN

Returns only rows that have a match in both tables:

Output
Run your code to see output here

LEFT JOIN

Returns all rows from the left table, even if there's no match in the right table (NULL fills the gaps):

Output
Run your code to see output here

JOINs Summary

TypeReturns
INNER JOINOnly rows with matches in both tables
LEFT JOINAll rows from left table + matches from right
RIGHT JOINAll rows from right table + matches from left
FULL JOINAll rows from both tables (matched where possible)
CROSS JOINEvery combination of rows (Cartesian product)

GROUP BY with Aggregates

Output
Run your code to see output here

Check Your Understanding

Which JOIN returns all students even if they're not enrolled in any course?

Exercise

Write a query that lists all courses with the count of enrolled students. Include courses with zero enrollments.

Python will load on first run

Questions & Discussion

Sign in to ask a question or join the discussion.

Loading comments...