Jump to content

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\" /]
Link to comment
https://forums.phpfreaks.com/topic/10996-sorting-by-name-through-id/
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--]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.