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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Join tbl1 information for two columns in tbl2

Author  Topic 

rickystyx
Starting Member

4 Posts

Posted - 2013-03-15 : 12:55:22
Any help will be appreciated.

Two tables: "Events", "Users"
"Events" columns are: Timestamp, UserID_A, UserID_B
"Users" columns are: UserID, UserName

I need to SELECT UserName_A and UserName_B from "Users" based on the UserID's in "Events". One column is easy enough, but I can't figure out how to join user information for multiple columns.

Thanks in advance!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-15 : 12:57:47
the hint is to link it twice each time based on different column

Make a try and post in case you face any issue

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

rickystyx
Starting Member

4 Posts

Posted - 2013-03-15 : 13:04:31
Looks like I figured it out. Thanks for the direction... it's much appreciated. Here's my query, with a few more details :)...

select s.sessionid as 'SessionID', s.evtime as 'TransferTime', u1.displayname as 'TransferringAgent', u2.displayname as 'ReceivingAgent'

from dbo.sessionevents s
inner join dbo.users u1
on s.evid = u1.id
inner join dbo.users u2
on s.evparam = u2.id
where
...

Thanks again, visakh16
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-15 : 13:10:23
cool...
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -