Maybe removing the square brackets and the as
can help you:
select product.id, t2.tt
from
product
join (
select product_id, avg(rating) tt
from reviews
where -- Your where conditions for the reviews table
) t2 on product.id = t2.product_id
where -- More where conditions
Also, consider not using a subquery. If your query is just like this, you could so something more simple:
select product.id, avg(reviews.rating) tt
from
product
join reviews on product.id = reviews.product_id
where -- All the conditions you need to define
If there are rows in the product
table that have no matching records in the reviews
table, but you still want them to be on the result, consider using a left join
:
select product.id, avg(reviews.rating) tt
from
product
left join reviews on product.id = reviews.product_id
where
reviews.product_id is null
or reviews.product_id is not null and (
-- All the conditions you need to define for the matching rows in the
-- reviews table
)