Tobias Funke
Tobias Funke

Reputation: 1814

INNER JOIN on 3 tables. SQL

Trying to make a query which prints out book title (in book table) and the author's name (in author table) but from a separate table that has all the book ID's of a certain sales rep. A picture of the tables in this link: https://i.sstatic.net/4whVP.png

My code so far is

SELECT book.title, author.fName, author.surname
FROM author 
INNER JOIN book ON author.aID = book.authorID 
INNER JOIN SeanWalshOrders ON book.isbn = SeanWalshOrders.bookID;

Upvotes: 0

Views: 5590

Answers (1)

Gord Thompson
Gord Thompson

Reputation: 123399

When I try to run the query as posted in the question I get the error

Syntax error (missing operator) in query expression 'author.aID = book.authorID INNER JOIN SeanWalshOrders ON book.isbn = SeanWalshOrders.bookI'.

When I re-construct that query using the Query Designer in Access it produces

SELECT book.title, author.fName, author.surname
FROM 
    (
        SeanWalshOrders 
        INNER JOIN 
        book 
            ON SeanWalshOrders.bookID = book.isbn
    ) 
    INNER JOIN 
    author 
        ON book.authorID = author.aID;

Access can be a bit fussy about parentheses in multiple JOINs.

Upvotes: 4

Related Questions