I have a database that contains 5 digit zip codes (ie 10001) and matching state abbreviations (ie NJ, NY, CA). I’ve found that some of the zip codes have multiple states (ie 10001 = NJ and 10001 = NY) which is wrong.
zip State
10001 NY
10001 NJ
10001 NY
10001 NY
... ...
Each State can have many zip codes, but each zip code should have only one state.
I’d like to find all the errors but can’t seem to write a query to do so.
Any suggestions?
A different approach, but rather than just give you a count, this gives you the states involved.
Once you’ve identified the duplicates and removed them, add a unique constraint on
zip,stateso you’re not doing this again next week, next month, etc.