tags:

views:

24

answers:

2

How do Find books (show their titles, authors and prices) that are on 'CIVIL WAR' (i.e., the title field contains 'CIVIL WAR'), available in 'AUDIO' format.

this is my schema * Books (bookid, title, author, year) * Customers (customerid, name, email) * Purchases (customerid, bookid, year) * Reviews (customerid, bookid, rating) * Pricing (bookid, format, price)

I did this but it did not work SELECT b.title, b.author, p.price FROM BOOKS b,PRICING p INNER JOIN books ON p.bookid WHERE b.title like '%CIVIL WAR%' AND p.format like '%AUDIO%' group by p.format, p.price

+1  A: 

Maybe:

 SELECT b.title, b.author, p.price 
 FROM BOOKS b
 INNER JOIN PRICING p ON p.bookid=b.bookid 
 WHERE b.title like '%CIVIL WAR%' AND p.format like '%AUDIO%' group by p.format, p.price
Andy Groff
+2  A: 

It looks like the ON clause is incomplete.

Try this:


SELECT b.title, b.author, p.price
FROM BOOKS b
INNER JOIN PRICING p ON p.bookid = b.bookid 
WHERE b.title like '%CIVIL WAR%' 
AND p.format like '%AUDIO%' group by p.format, p.price

See the = b.bookid at the end of the INNER JOIN? That's the issue.

JoshD
thank you it works. I just changed to group by b.title and worked
Sasha Becon
You're welcome Sasha. Don't forget to select an answer for this question. And welcome to StackOverflow!
JoshD
can i ask another question?
Sasha Becon
@Sasha: You should mark this response as an "Accepted Answer" then.
aip.cd.aish
Sure. Ask as many as you like.
JoshD
# For each year, 'JOHN CHAMBERS' purchased at least one book, find the number of books purchased. That is, the output should be a set of tuples, each indicating a year and the number of books purchased by 'JOHN CHAMBERS' in that year. here is what i have SELECT customerid, p.yearFROM PURCHASES p, BOOKS
Sasha Becon
You should create a new question for this on the main page. That way, everyone will see it and you'll get plenty of responses.
JoshD