MySQL: Limit output according to associated ID

Posted by Jess on Stack Overflow See other posts from Stack Overflow or by Jess
Published on 2010-03-16T23:08:53Z Indexed on 2010/03/17 0:01 UTC
Read the original article Hit count: 225

Filed under:
|

So here's my situation. I have a books table and authors table. An author can have many books... In my authors page view, the user (logged in) can click an author in a tabled row and be directed to a page displaying the author's books (collected like this URI format: viewauthorbooks.php?author_id=23), very straight forward... However, in my query, I need to display the books for the author only, and not all books stored in the books table (as i currently have!) As I am a complete novice, I used the most simple query of:

SELECT * FROM tasks_tb 

This returns the books for me, but returns every single value (book) in the database, and not ones associated with the selected author. And when I click a different author the same books are displayed for them...I think everyone gets what I'm trying to achieve, I just don't know how to perform the query. I'm guessing that I need to start using more advanced query clauses like INNER JOIN etc. Anyone care to help me out :)

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql