member group query

Reply

Join Date: Jul 2005
Posts: 1
Reputation: jbkielis is an unknown quantity at this point 
Solved Threads: 0
jbkielis jbkielis is offline Offline
Newbie Poster

member group query

 
0
  #1
Jul 11th, 2005
Hello everyone. Thanks in advance for any help.

I have two tables, a groups table and a members table.

The groups table contains the main groups, such as group1, group2, group3.

id | name | description


The members table contains user''s ids and the group id.

id | userid | groupid

I am having difficulty creating a select query that returns all the groups for which a user is a member, including the total amount of members in each group.

Basically, I am trying to achieve the following given a specific user:

GROUP | MEMBERS

Group1 | 12
Group2 | 15

Any ideas how to do this in a single select statement. Thanks very much
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 71
Reputation: Kate Albany is an unknown quantity at this point 
Solved Threads: 1
Kate Albany Kate Albany is offline Offline
Junior Poster in Training

Re: member group query

 
0
  #2
Jul 12th, 2005
Try:

select g.name, count(1)
from group g
where g.id in (select u.groupid from user u where u.userid = <put_userid_here>)
group by g.name
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MySQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC