|
I am writing in reference to a previous post. I am trying to combine two tables that do not have a common column name but do share two columns with SOME common data. I will explain in this example: Table A- AcctID, Table B- PartnerID, AcctValue The column I am truly interested in is AcctValue which is in table B. I want to find the AcctValue for each AcctID. The problem is Partner does not match ALL AcctID only small portion. There are 4,000 AcctID and they only match up with 2,000 PartnerID so I am not able to find the AcctValue for 2,000 AcctID. This is what I've done but only shows me 2,000 AcctID: How can I get all the AcctId and their AcctValues? I am sure there is a way to do this but I can seem to figure it out
(comments are locked)
|
|
If there is no column that reliably corresponds to AcctID then there is no way to reliably associate an AcctValue with an AcctID.
(comments are locked)
|


@sqllearner If you have some accounts in A which do not have any matching records (by partner id) in table B then the SUM(tb2.AcctValue) for these is null. You can still list all 4,000 accounts by simply replacing the inner join with left join in your query. It also looks like you probably have zero to many relationships between tables A and B (otherwise why would you use the SUM). If this is the case then your query is also missing the GROUP BY: