I am using SSMS 2008. Should be a simple solution to this. I am trying to pull all records from table A, but only pull in matching records from tables B and C. The problem is that if I left join tables B and C, it returns records where all 3 of these tables intersect instead. Like if I query this combined merge, I get non-NULL values for every row for both B and C.
Here is my pseudocode:
SELECT A.ID, B.ID, C.ID
FROM A
LEFT JOIN B ON B.ID = A.ID
LEFT JOIN C ON C.ID = A.ID
In answer to your questions, I am sorry I forgot the “LEFT”, but I just added it above. If table A has 9 rows and B has 2 rows and C has 3 rows, then what I want to see above is where table A intersects B and where A intersects C.
So in the scenario just described, assuming that the Table B rows are all different than the Table C rows, then I want to see a total of 5 rows; 2 from B and 3 from C. Make sense?
The ideal way to do this is with a
LEFT JOIN. I believe (though it’s unclear from your question) that the problem you have is multiple rows perA.ID.If
A.IDmatchesB.IDANDC.IDthen you are getting two rows for this, and would like one consolidated row.I think maybe you had your
JOINconditions mixed up in your test query. This is working fine for me in testing. Try the below query:Output is: