Learn with Abdou

Chapter 7 · Concept 5 of 6 · Practice

Follow a loan through its keys

three-table joins, and which branch is which · level 1 of 6

Opening your saved work…

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

Follow a loan through its keys · three-table joins, and which branch is which · level 1 of 6

A loan names three things

Level 1: Watch it answered · Exercise 1 of 1

The first three loans with the ids of the member and the tool they connect. Watch the two joins, then run it.

Data: Twin Ports Tool Library.

Why it works, clause by clause

  1. FROM loans l: each output row is a loan, so loans is the hub.
  2. JOIN members m ON m.id = l.member_id: follow the loan's member_id to its member.
  3. JOIN tools t ON t.id = l.tool_id: follow the loan's tool_id to its tool. Each join starts from the hub, not from the previous parent.
  4. ORDER BY l.id LIMIT 3: a repeatable preview.

From the reading: Follow a loan through its keys, paragraph 1

The queryOpening the database…
SELECT l.id AS loan_id, m.id AS member_id, t.id AS tool_id
FROM loans l
JOIN members m ON m.id = l.member_id
JOIN tools t ON t.id = l.tool_id
ORDER BY l.id
LIMIT 3;
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.