Never borrowed or not returned?
LEFT JOIN and the unmatched row · level 1 of 6
Opening your saved work…
Sign in to save across devices → · Download your guest work before switching accounts.
Never borrowed or not returned? · LEFT JOIN and the unmatched row · level 1 of 6
Ten tools nobody has borrowed
Which tools have never been borrowed? Watch the query answer it, then run it yourself.
Data: Twin Ports Tool Library.
Why it works, clause by clause
- FROM tools t: start from the table whose rows must all survive. Every tool, borrowed or not.
- LEFT JOIN loans l ON l.tool_id = t.id: pair each tool with its loans. A tool with no loans still gets one row, with NULL in every loan column.
- WHERE l.id IS NULL: keep only the rows where the pairing found nothing. That is the gap.
- ORDER BY t.name: a repeatable order, so the list reads the same every time.
From the reading: Never borrowed, or not returned?, paragraph 2
SELECT t.name, t.category
FROM tools t
LEFT JOIN loans l ON l.tool_id = t.id
WHERE l.id IS NULL
ORDER BY t.name;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.