Ich habe eine n-zu-m Beziehung zwischen Author
und Book
.SQL wählen in n zu m Beziehung
Tabelle Autor
ID Name
1 Follett
2 Rowling
3 Martin
Table Book
ID Title Category
1 A Dance with Dragons Fantasy
2 Harry Potter Fantasy
3 The Key to Rebecca Thriller
4 World without end Drama
Tabelle BOOK_AUTHOR
authorId bookId
1 3
2 2
3 1
1 4
Es gibt eine Menge mehr Autoren und Bücher im System. Jetzt möchte ich alle Autoren auswählen, die ein Buch im Genre "Fantasy" haben.
Dies ist, was ich mit so weit kam:
select distinct a.id
from author a, book b, written w
where w.authorId = a.id and w.bookId = b.id and b.category = "Fantasy";
Ich frage mich, wie diese Abfrage zu optimieren, da vor allem Büchertisch wirklich groß ist.
Haben Ihre Tabellen Indizes? Auf welchen Spalten? –