Bryan
Bryan

Reputation: 71

How to merge duplicate rows based on columns that are not empty?

I'm dealing with the problem of working with a dirty customer database. There are many duplicates due to different spellings and maintenance quality of the data. For example the data looks like this:

enter image description here

My goal is to merge rows generically based on the name, so the empty columns are automatically filled with the value contained in another row: enter image description here

Is there a way in SQL to do something like that?

Upvotes: 0

Views: 341

Answers (1)

persian-theme
persian-theme

Reputation: 6638

SELECT Name,
       MAX(Address) Address,
       MAX(Zip) Zip,
       MAX(Mail) Mail,
       MAX(Phone) Phone,
       MAX(City) City
FROM customer
GROUP BY Name

Upvotes: 1

Related Questions