I have 2 tables:
books (isbn, title, author, category1, category2, category3)
ratings (id, isbn, rating, comment, date entered, submitted by)
They are realted by isbn (primary key in books table). I need the quwry to tell me what the top 10 rated books are and the top 10 rated books by category.
At the moment I'm trying to work out the category query. In Access this works (it was autogenerated when I used a wizard:
SELECT ratings.isbn AS ISBN, Avg(ratings.rating) AS Average_Rating, books.title AS Title, books.author AS Author
FROM books, ratings
WHERE (((books.isbn)=[ratings].[isbn]))
GROUP BY ratings.isbn, books.title, books.author
ORDER BY Avg(ratings.rating) DESC;
I've translated it, for mySQL/PHP as this:
SELECT ratings.isbn AS ISBN, Avg(ratings.rating) AS Average_Rating,
books.title AS Title, books.authors AS Authors
FROM books, ratings
WHERE books.isbn=ratings.isbn
AND books.category1 = '$ratings_category'
GROUP BY ratings.isbn, books.title, books.author
ORDER BY Avg(ratings.rating) DESC
2 problems:
1. I get an error saying "Invalid use of group function"
2. I want to be able to say books.category1 = '$ratings_category'
OR books.category2 = '$ratings_category' OR books.category3 = '$ratings_category'
What is going wrong with Q1 and can you use OR like I say in Q2?





Bookmarks