cpeterson
cpeterson

Reputation: 63

Insert null rows where needed

I am trying to preserve the structure of the results and replace the player id's with player firstnames. IE I want the nulls to stay where they are to preserve the ordering. see below:

Step 1) replace FK_WinnerID with FirstName and preserve the nulls.

enter image description here

Problem is sql statement is removing nulls

enter image description here

This is what it should look like:

enter image description here

Upvotes: 0

Views: 44

Answers (2)

Conrad Frix
Conrad Frix

Reputation: 52645

When you have

FROM A LEFT JOIN B

That means you want everything in A and matching records in B

But you want everything from B and matching records in A so you need to do either

FROM B LEFT JOIN A

OR

FROM A RIGHT JOIN B

Upvotes: 2

cpeterson
cpeterson

Reputation: 63

SELECT FirstName
FROM Players right join TournamentPrizes
ON Players.PlayerID = TournamentPrizes.FK_WinnerID
WHERE FK_TournamentID=1043 
order by TournamentPrizes.Place ASC

Upvotes: 0

Related Questions