user16045271
user16045271

Reputation:

Why does this MySQL error near group by statement?

I want to group my table with mem_num and it appears error saying that :

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group by m.mem_num' at line 6.

Here's my code.

select m.mem_num, count(d.vid_num) as total
from membership m
inner join rental r on m.mem_num = r.mem_num
inner join detailrental d on r.rent_num = d.rent_num
having count(d.vid_num) > 1
group by m.mem_num;

For a clearer view click here to view the image : output query

Upvotes: 2

Views: 177

Answers (1)

nbk
nbk

Reputation: 49385

HAVING belongs after the GROUP BY

select m.mem_num, count(d.vid_num) as total
from membership m
inner join rental r on m.mem_num = r.mem_num
inner join detailrental d on r.rent_num = d.rent_num
group by m.mem_num
having count(d.vid_num) > 1;

Upvotes: 1

Related Questions