thunderroms Posted June 2, 2006 Share Posted June 2, 2006 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\" /] Quote Link to comment https://forums.phpfreaks.com/topic/10996-sorting-by-name-through-id/ Share on other sites More sharing options...
jeremywesselman Posted June 2, 2006 Share Posted June 2, 2006 [!--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--] Quote Link to comment https://forums.phpfreaks.com/topic/10996-sorting-by-name-through-id/#findComment-41062 Share on other sites More sharing options...
thunderroms Posted June 2, 2006 Author Share Posted June 2, 2006 Nice, it works just like i wanted, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/10996-sorting-by-name-through-id/#findComment-41098 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.