Jump to content

combining this into one query?


gnznroses

Recommended Posts

let's assume I have two tables:

 

users, which includes one column called id, and then a bunch of others)

groups, which contains user_id and group_id

 

i need to get a list of users that are in a specific group, and also a list of all of the groups each user is in.

i know i could get a list of the users that are in the group, and then run a second query for each user to get the list of groups for each, but is there a way to do this in one query?

 

if i use a Where that includes groups.user_id = users.id then i get duplicates in the user results. if i add Group By to fix that, then i no longer have the list of groups for each user.

 

advice?

Link to comment
https://forums.phpfreaks.com/topic/136986-combining-this-into-one-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.