Jump to content


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


Sorting by name through ID...?

Recommended Posts

Hello, it may be something very simple that I'm missing, but I cant seem to figure this out...

we have 2 tables and a linking table:
Users (UserID, UserName, etc)
Group(GroupID, GroupName, etc)
UsersInGroup(LinkID, GroupID, UserID)

Simple enough...

Now, I want to display the users where GroupID = 1... So I select all in UsersInGroup where GroupID = 1; that gives me all the users...

Now, I want to sort them by name... How would I do that? I cant use the ORDER command in the SQL code because the username isnt even in the UsersInGroup, only the UserID exists there.

Thank you in advance! [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Share this post

Link to post
Share on other sites
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * [color=green]FROM[/color] [color=orange]usersingroup[/color] INNER [color=green]JOIN[/color] users on usersingroup.UserID [color=orange]=[/color] users.UserID [color=green]WHERE[/color] GroupID [color=orange]=[/color] 1 [color=green]ORDER BY[/color] UserName ASC; [!--sql2--][/div][!--sql3--]

I have created the same setup that you have and this should give you the proper results.

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--]

Share this post

Link to post
Share on other sites


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.