Kodewick
Jetzt lernen →
Grundlagen←→0 / 70

Nie ausgeliehen

#049GrundlagenLEFT JOIN + IS NULL5 Min.

Die Bibliothek will die Bücher, die niemand ausgeliehen hat, gut sichtbar aufstellen. Mach books LEFT JOIN loans, behalte nur die Bücher ohne Ausleihe (bei denen loans.id leer ist) und wähl ihren title aus.

Die Tabellen
books
  • idPK
  • title
  • author
  • genre
  • pages
  • year
loans
  • idPK
  • book_idFK
  • reader
  • days

loans.book_id → books.id

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 Zeilen
loans
idbook_idreaderdays
11Leo14
22Nora7
31SamNULL
44Leo21
55NoraNULL
63Ivy10
72Sam5
87Ivy12
8 Zeilen
query.sql
SELECT books.title
FROM books
LEFT JOIN loans ON loans.book_id = books.id
-- dein Code hier: WHERE loans.id IS NULL behält die Bücher ohne Treffer
;
Strg + Enter führt den Code auch aus
Ergebnis

Ausführen zeigt, was deine Abfrage liefert. Wenn es passt, drück auf Abgeben.