954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

member group query

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

jbkielis
Newbie Poster
1 post since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

Try:

select g.name, count(1)
from group g
where g.id in (select u.groupid from user u where u.userid = )
group by g.name

Kate Albany
Junior Poster in Training
71 posts since Jun 2005
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You