Struggling with MySQL query using joins -


I have 3 tables to keep information about books:

  Books - ---- ID Title Authors ------- ID names books_to_authors ---------------- book_id author_id  

When a book Information is displayed, I want to be able to select any other books by the same author.

I have the current book id available from the first question, but I have not figured out what items I need can be many authors, obviously with just one of them it will be easy, so I'm really struggling with this. Any help will be very much appreciated!

I think there is nothing to do. Just looking at the current book id with ? and it will give you all the books by the same author.

  SELECT b. * Books b INNER JOIN books_to_authors b2a ON b2a.book_id = b.id WHERE b2a.author_id IN (books_to_authors WHERE book_id =?) Select author_id  

if you want to exclude that book If they are currently viewing, then you can change the question like this:

  SELECT b * Join b from the books books_to_authors b2a b2a.book_id = b.id WHERE b2a.author_id IN (SELECT author_id books_to_authors WHERE book_id =?) And B.ID & lt; & Gt; ?  

Comments