Jump to content


Sorting by name through ID...?

  • Please log in to reply
2 replies to this topic

#1 thunderroms

  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 02 June 2006 - 01:07 AM

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\" /]

#2 jeremywesselman

  • Members
  • PipPipPip
  • Advanced Member
  • 154 posts
  • LocationIndependence, KY

Posted 02 June 2006 - 01:46 AM

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * FROM usersingroup INNER JOIN users on usersingroup.UserID = users.UserID WHERE GroupID = 1 ORDER BY 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--]

#3 thunderroms

  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 02 June 2006 - 04:57 AM

Nice, it works just like i wanted, thanks!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users