Reputation: 13
I have a table with two columns that I want to join to another table on one column.
fkUserIdOpenedBan
and FKuserIdClosedBag
FkUserID
and UserName
Both columns link to FkUserID
I need to be able to join them so that when I select I can see the username of the person who opened the bag and who closed the bag.
Do I need to create a temp table then join it?
I'd rather not do that as I will already be creating other temp tables in this report.
Upvotes: 1
Views: 85
Reputation: 115
You join the table twice:
SELECT A.fkUserIdOpenedBag, B.UserName As OpenedName, A.fkUserIdClosedBag, C.UserName AS ClosedName FROM TableA AS A
INNER JOIN TableB AS B ON A.fkUserIdOpenedBag = B.fkUserId
INNER JOIN TableB AS C ON A.fkUserIdClosedBag = C.fkUserId
Upvotes: 1