Craig Gibbs
Craig Gibbs

Reputation: 13

Joining multiple columns to one column

I have a table with two columns that I want to join to another table on one column.

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

Answers (1)

trailer
trailer

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

Related Questions