SQL To List Users From Multiple User Groups

TheBigK

Well-known member
I'm trying to list all the users from various user groups. I can't figure out the SQL to get the list. My best attempt so far is this:
Code:
SELECT * from xf_user WHERE user_group_id IN (3,4,5,6);

What's the right way to do this? Is there any easy alternative (using inbuilt function)?
 
Update: I've been trying to get this right and now wondering if I really need to use 'JOIN'. I've a hunch that this is simpler than I think.
 
Update: I've been trying to get this right and now wondering if I really need to use 'JOIN'. I've a hunch that this is simpler than I think.

Try this query:

Code:
SELECT u.username AS 'User',  g.title AS 'User Group'
FROM xf_user AS u
LEFT JOIN xf_user_group AS g ON ( u.user_group_id = g.user_group_id )

If you are using a custom prefix for your db tables, then replace xf_ with that prefix in the query above.
 
Back
Top Bottom