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
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
- FROM loans l: each output row is a loan, so loans is the hub.
- JOIN members m ON m.id = l.member_id: follow the loan's member_id to its member.
- 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.
- ORDER BY l.id LIMIT 3: a repeatable preview.
From the reading: Follow a loan through its keys, paragraph 1
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;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.