Say I have a database for storing info on books, and I want to search by book title or author.
Books can be by multiple authors, so this is a many-many relationship.
I have normalised my tables and ended up with this:
Books(book_ID(pk), book_name)
book_authors(book_ID(pk), author_id(pk))
authors(author_id(pk), author_name)
I have in the database two authors, say "Mr Smith" and "Mr Jones", and 3 books, "Book A", "Book B" and "Book C"
"Book A" is written by Mr Smith
"Book B" is written by Mr Smith and Mr Jones
"Book C" is written by Mr Jones
How can I now search for a book that is written by BOTH Mr Jones AND Mr Smith?
It should return just Book B.
It can be done with a nested SELECT Query in SQL, but then what if there are three authors to a book, I'd have to add another layer of nesting.
Is there a more efficient way to do this?