Reputation: 13
I have 2 tables, food and score.
Food
id
name
picture
score
id
score
food_id
.I want to query food that have average score above 7:
select * from food where (select avg(score) from score group by food_id)>=7
But this returns
error #1242 - Subquery returns more than 1 row.
Upvotes: 1
Views: 49
Reputation: 4751
Try out this:
select fd.* from food fd
inner join score sc on fd.id=sc .food_id
group by food.id
having avg(sc.score)>=7
Upvotes: 1
Reputation:
Try this
SELECT * FROM food f INNER JOIN score s
ON f.id = s.food_id
WHERE avg(s.score)>=7
GROUP BY f.food_id
Upvotes: 1