Skip to content
Advertisement

SQL Finding Dupe Names with Distinct ID

I have a list of customers, and a bunch of them are duplicates (‘Acme Inc’, ‘Acme, Inc’, ‘Acme Inc.’, ‘Acme, Inc.’) They all have different IDs. BUT, each ID also has multiple addresses. Something like…

I have a function that normalizes the name so the first 6 would all be ‘Acme’ and the last two ‘Plumbers’.

What I want is a list of the ID and Name where there are duplicate. The goal is a report of records with unique IDs and duplicate names.

I tried this:

I also tried to put them into [dump_names] table and join the two, but I keep getting multiple records from the same ID

I think I’m overthinking this or the migraine I’m sporting is clouding my thinking. Either way, I appreciate the help.

Advertisement

Answer

One approach would use a CTE to find the distinct counts of name variants for each normalized name. Then, join to your current table and retain only records which had more than one name variant.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement