との間にはn対mの関係がAuthor
ありBook
ます。
テーブル作成者
ID Name
1 Follett
2 Rowling
3 Martin
テーブルブック
ID Title Category
1 A Dance with Dragons Fantasy
2 Harry Potter Fantasy
3 The Key to Rebecca Thriller
4 World without end Drama
テーブルbook_author
authorId bookId
1 3
2 2
3 1
1 4
システムにはもっとたくさんの著者と本があります。ここで、「ファンタジー」というジャンルの本を持っているすべての著者を選択したいと思います。
これは私がこれまでに思いついたものです:
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";
特にテーブルブックは本当に大きいので、このクエリを最適化する方法を考えています。