User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 423,879 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,196 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 2190 | Replies: 1
Reply
Join Date: Jul 2005
Posts: 1
Reputation: jbkielis is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jbkielis jbkielis is offline Offline
Newbie Poster

member group query

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Posts: 71
Reputation: Kate Albany is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Kate Albany Kate Albany is offline Offline
Junior Poster in Training

Re: member group query

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MySQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 4:37 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC