2
I’m trying to update a table in my database into two new columns, one that brings the average of the ratings and one that brings the number of ratings.
These data are obtained through two tables, the relationship between them is the id
and the product_id
.
I tried the following code:
UPDATE product
INNER JOIN
product_review ON product.id = product_review.product_id
SET
product.review_rating = (
SELECT AVG(product_review.rating) WHERE state='approved'
);
But it returns the average of all products and not of each one separately, some suggestion?