Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
JohnG1
Starting Member
2 Posts |
Posted - 2009-06-24 : 01:00:49
|
| I'm quite new to SQL, but seem to have a fair grasp of the basics. This one though has me stumped.I have one table which lists Tasks and may have a couple of IDs for Team Members - ManagerID and AssignedID which relates to a Users table.I'm trying to join these two tables (Tasks and Users) to include the Manager and Assigned person names.eg.TASKSTaskID ManagerID AssignedID1 1 2USERSUserID Name1 Tom2 JerryI'm struggling to return the Users.Name twice for both the ManagerID and AssignedID. The data that should be returned would be:TaskID ManagerName AssignedName1 Tom JerryAny help on how to achieve this would be appreciated.ThanksJohn |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-06-24 : 01:06:23
|
use table aliasselect t.TaskID, m.Name as ManagerName, a.Name as AssignedNamefrom TASKS t inner join USERS m on t.ManagerID = m.UserID inner join USERS a on t.AssignedID = a.UserID KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
JohnG1
Starting Member
2 Posts |
Posted - 2009-06-24 : 01:50:14
|
| Hi KHMany thanks for the quick response. Just what I needed!CheersJohn |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-06-24 : 01:51:27
|
welcome KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|