I have a table 1 (MID, SSN, ...) MID is primary key and table 2 (ID, SSN, StateCode..) where ID and SSN make up the primary key. I'm trying to display all columns from table 1 along with StateCode from table 2 matching it against SSN. Tbl 1 has 50 rows and some have same SSN values.
If no SSN match is found from table 2, displaying a NULL in StateCode is acceptable, so I chose left join. Here is my query
Select
tbl1.*, tbl2.StateCode
from
tbl1
left outer join
tbl2 on tbl1.SSN = tbl2.SSN
I'm looking to retrieve 50 records, but I get 70, rows that contain the same ssn value in tbl1 ends up duplicated in the final output. What is going wrong?
SELECT COUNT(SSN), COUNT(DISTINCT SSN) FROM table2.