Kodewick
Start learning →
Basic←→0 / 70

Never borrowed

#049BasicNULLJOIN5 min

The library wants to put the books nobody has borrowed somewhere easy to see. Do books LEFT JOIN loans, keep only the books with no loan (where loans.id is empty), and pick their title.

The tables
books
idtitleauthorgenrepagesyear
1The Night GardenMia Lanestory2102015
2Stars for KidsTom Hartscience962020
3Lost at SeaMia Lanestory3402011
4Easy BreadRosa Bellfood1282019
5The Bug BookTom Hartscience642022
6Soup DaysRosa Bellfood1502008
7The Red KiteAnn Colestory1802021
8Rocks and RiversAnn Colescience2202017
8 rows
loans
idbook_idreaderdays
11Leo14
22Nora7
31SamNULL
44Leo21
55NoraNULL
63Ivy10
72Sam5
87Ivy12
8 rows
query.sql
SELECT books.title
FROM books
LEFT JOIN loans ON loans.book_id = books.id
-- your code here: WHERE loans.id IS NULL keeps the books with no match
;
Ctrl + Enter runs too
Result

Run shows what your query gives. When it looks right, Submit.