Learn with Abdou

Chapter 7 · Concept 1 of 6 · Practice

Join on a relationship, not a coincidence

INNER JOIN ON a key · level 1 of 6

Opening your saved work…

Sign in to save across devices → · Download your guest work before switching accounts.

Join on a relationship, not a coincidence · INNER JOIN ON a key · level 1 of 6

Eight tools and the branch that owns them

Level 1: Watch it answered · Exercise 1 of 1

Which branch owns each of the first eight tools? Watch the join answer it, then run it.

Data: Twin Ports Tool Library.

Why it works, clause by clause

  1. FROM tools t: the report is about tools, so start there and call the table t.
  2. JOIN branches b ON b.id = t.branch_id: for each tool, attach the one branch whose id equals the tool's branch_id. That is the foreign key meeting the primary key it points to.
  3. WHERE t.id <= 8: keep the first eight tools. The filter is on the tool, so it is written with the tool's alias.
  4. ORDER BY t.id: a repeatable order.

From the reading: Join on a relationship, not a coincidence, paragraph 1

The queryOpening the database…
SELECT t.id AS tool_id, t.name AS tool_name, b.name AS owning_branch
FROM tools t
JOIN branches b ON b.id = t.branch_id
WHERE t.id <= 8
ORDER BY t.id;
Open in the playground

Query results

Run it to see the result here.

Run it to see the result here.

Practice here is evidence for you and your instructor, never a grade. Grades live in Canvas.