0

I wanted to create a nested query that on the outside gets the title and price from a table called 'Books' while having a nest inside the query that gets the Author's First and last name for that specific book. I'm just a little confused on the Inner Joins and where they need to be placed. This is as close as I was able to get with it but this just prints every author for every book.

select Title, AuthorFirst, AuthorLast,Price from Book
JOIN
(select AuthorLast,AuthorFirst from Author 
INNER JOIN Wrote on Author.AuthorNum = Wrote.AuthorNum 
INNER JOIN Book on Wrote.BookCode = Book.BookCode group by title desc)Auth;

This joins the tables that I need but it prints every author in the DB with every book in the database. I think it has something with my Inner Joins not being specific enough.

2
  • A minimal reproducible example includes DBMS (with version), a clear specification, cut & paste & runnable code (with small representative input) (format table initializations as tables) & diffable (hence ordered) desired output. But absolute basics of debugging say: Show that your program does what you expect as it goes through (sub)expressions by saying what that is & showing that it actually does it via incremental output. On adding problem code that you can't fix, research (the manual & the web). Repeat, minimizing working & wrong code. Then ask re the (small) difference between working & non-working examples. Commented Dec 4, 2018 at 6:57
  • Why do you specifically need to use a nested query ? Looks like you don’t need that to achieve your goal Commented Dec 4, 2018 at 8:02

1 Answer 1

1

The group by clause is wrong and you should remove it. Once you do that, there's no need to nest the joins - you could just have several joins in the same query:

SELECT     Title, AuthorFirst, AuthorLast, Price
FROM       Book
INNER JOIN Wrote ON Author.AuthorNum = Wrote.AuthorNum 
INNER JOIN Book ON Wrote.BookCode = Book.BookCode
Sign up to request clarification or add additional context in comments.

1 Comment

It is required that I nest unfortunately or else I would already have this done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.