SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Join tbl1 information for two columns in tbl2
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rickystyx
Starting Member

4 Posts

Posted - 03/15/2013 :  12:55:22  Show Profile  Reply with Quote
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

India
52309 Posts

Posted - 03/15/2013 :  12:57:47  Show Profile  Reply with Quote
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 - 03/15/2013 :  13:04:31  Show Profile  Reply with Quote
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

India
52309 Posts

Posted - 03/15/2013 :  13:10:23  Show Profile  Reply with Quote
cool...
welcome

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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000