I am trying to come up with a query in MS Acess to compare two tables. I am basing my comparison on 4 fields postal_code, city, state and country.
I want to be able to get all records in table1 that do not have a match in table2.
Here is my sample data. I am expecting 2 records in the query output, that I have marked with a “*”
table1
======
POSTAL_CODE CITY STATE_PROV COUNTRY_CODE
*12345 Union NJ US
45678 Hillside NJ US
*45678 Union NJ US
table2
======
POSTAL_CODE CITY STATE_PROV COUNTRY_CODE
45678 Hillside NJ US
Here is what I have tried, but does not do the job:
SELECT DISTINCT table1.*
FROM table1 LEFT JOIN table2 ON table1.POSTAL_CODE=table2.POSTAL_CODE
WHERE ((table2.POSTAL_CODE Is Null));
How do I accomplish this? Please let me know any suggestion.
Thank you.
The
ONexpression for theLEFT JOINshould include all 4 of those fields you want to match. I also left outDISTINCT.