Analytics & Joins · 9 min read · Beginner
JOINs & Table Relationships
Connect normalized tables using primary keys, foreign keys, INNER JOIN, and LEFT JOIN.
What you'll learn
- Combine matching rows from two tables with INNER JOIN ... ON
- Keep unmatched rows from the left table using LEFT JOIN
- Use concise table aliases (c, e) to keep JOIN queries readable
Relational databases avoid repeating data by splitting entities into separate tables (like learners and courses) linked by IDs.
INNER JOIN: Returns only rows that have a match in both tables.LEFT JOIN: Returns all rows from the left table, withNULLfor columns when the right table has no match.
Fill-in-the-Blank Exercise
Join Enrollments to Courses
Join enrollments (e) with courses (c) where e.course_id matches c.id.
SELECT e.learner, c.title
FROM enrollments e
JOIN courses c e.course_id = c.id;Try It Yourself
Try changing LEFT JOIN to INNER JOIN below and watch what happens to Noah (who has no certificate yet)!
SQLLEFT JOIN vs. INNER JOIN
Query Result (In-Browser SQLite)
Click Run SQL to execute this query against a live in-browser SQLite database.
Check Your Understanding
Score: 0 / 1
1. Which JOIN keeps every row from the left table even when there is no matching row in the right table?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.