Search code examples
phpmysqlcomputer-science

Sorting through 3 tables MYSQL


Hello I am trying to sort through these 3 Tables

I need to create a query that goes through the 'Author' Table,

grabs the author num

Then goes to the 'Wrote' table to find the 'BookCode' from the AuthorNum of the last table

Then to finally go through the Book table to list the title of the book and the first name and last name of the author.

I was thinking of using a join table but am not too solid on my uinderstanding on how it works. Nested select statements was my next guess but I can't get them to go through so many tables.

If anyone could help me that would be fantastic, thank you.


Solution

  • You want to use INNER JOINS to match up the data

    SELECT *
    FROM authors AS a
    INNER JOIN wrote AS w
      ON a.AuthorNum = w.AuthorNum
    INNER JOIN book AS b
      ON w.BookCode = b.BookCode