There is such a structure database:

enter image description here

It is necessary to display a specific group if it has more than 5 users, tried such a query, but it does not work:

SELECT GROUP.NAME FROM GROUP JOIN USER_GROUP ON GROUP.ID = USER_GROUP.GROUP_ID WHERE USER_GROUP.GROUP_ID = '3' HAVING COUNT(USER_GROUP.GROUP_ID = '3') > 5 

How to fix?

  • Well, check that you need more than 5 users ? why in having you group then? having count(user_id) > 5 - teran 5:53 pm
  • Now Mike will come and tell you how. Here you need to use GROUP BY GROUP.ID , WHERE USER_GROUP.GROUP_ID = '3' - remove, HAVING COUNT(USER_GROUP.GROUP_ID = '3') > 5 replace with HAVING COUNT(*) > 5 - ArchDemon

1 answer 1

 SELECT GROUP.NAME FROM GROUP JOIN USER_GROUP ON GROUP.ID = USER_GROUP.GROUP_ID WHERE USER_GROUP.GROUP_ID = '3' GROUP BY GROUP.ID HAVING COUNT(USER_GROUP.USER_ID) > 5