I am not very experienced in MySQL queries so I might be doing something wrong. Simplified my query is like this:
SELECT item.*, AVG(itemRating.rating) as 'rating', COUNT(itemRating.rating) as 'ratingCount'
FROM item, itemRating
WHERE item.id IN (...)
AND itemRating.item_fk = item.id
GROUP BY itemRating.item_fk
It works fine, except for when an item has no rating (no record in the itemRating table). Is there any way I can solve this without losing information?
SELECT item.*, AVG(itemRating.rating) as 'rating' ... GROUP BY itemRating.item_fkIt seems to me that you need to write eitherSELECT itemRating.item_fk, AVG(itemRating.rating) as 'rating' ... GROUP BY itemRating.item_fkorSELECT item.*, AVG(itemRating.rating) as 'rating' ... GROUP BY item.*(You can't writeGROUP BY item.*I did that because I don't know what columns you have in theitemtable, you need to specify every column of theitemin theGROUP BYclause)