dongye9991 2015-11-17 07:52
浏览 60
已采纳

使用中间表从另一个表中获取信息

Here I have three tables authors, books_has_authors and books.

Books_has_author is an intermediate table which contains only the primary keys form other two tables. I am trying to write an sql query which will return me all the books name written by a particular author. I am new to relational database concepts as well as writing queries for relational databases. I know some join queries but I'm really confused how to use them for fetching information through an intermediate table. Any help will be appreciated ! :)

enter image description here

  • 写回答

3条回答 默认 最新

  • dou4121 2015-11-17 07:57
    关注

    You only need to add an additional JOIN, like this:

    SELECT b.book_id, b.book_name, a.author_id, a.author_name
    FROM books b
    JOIN books_has_author ba ON ba.books_book_id = b.book_id
    JOIN author a ON ba.author_author_id = a.author_id
    WHERE a.author_id = xxx
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?