Chapter 4 Revision: Multi-Table Joins & Relationships 🔗
Connecting data across tables using keys is what makes relational databases the most dominant data paradigm in software engineering.
Review your mental models and join intuition before advancing to Data Definition & Manipulation!
Active Recall Flashcards 🎴
Click each card to test your retention before checking the answer.
What is the difference between an INNER JOIN and a LEFT JOIN?
LEFT JOIN: Returns all rows from the left table, filling in NULLs for columns of the right table when no match exists.
How do you find parent records that have ZERO related child records using a LEFT JOIN?
LEFT JOIN to the child table on the foreign key, and filter with WHERE child_table.id IS NULL.Why should you count 'child_table.id' instead of 'COUNT(*)' when aggregating rows after a LEFT JOIN?
COUNT(*) will incorrectly count 1, whereas COUNT(child.id) ignores NULL and correctly counts 0.What is a Cartesian product, and which SQL join produces it?
What is a Self Join and what is its most common practical use case?
Chapter 4 Mastery Quiz 🎯
Table 'Users' has 10 rows. Table 'Orders' has 4 rows. 3 users placed 1 order each, and 1 user placed 1 order. 6 users placed zero orders. How many rows will 'SELECT * FROM Users INNER JOIN Orders ON Users.id = Orders.user_id;' return?
Ready for Chapter 5? 🚀
You've mastered querying, filtering, grouping, and joining across multi-table relational models!
Now it's time to learn how tables are created, altered, and populated:
Next up: Chapter 5 — Data Definition & Data Manipulation (CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, and Constraints)!