'Combine Duplicates in a Table using MySql. Dupes defined by one field, combine/concatanetate disparate values in other fields
I have a table withe about 1000 duplicate records based on a Name1 Field. Dupes can have different values in two other fields e.g. Acronym and ParentID. There are 4 scenarios:
- All records have null values
- One Record has NULL value the other does not
- Both records have different values.
- Botrh records have the same values
- In the case of #1 of course I want a single record with NULL value in the selected field. In
- In the case of #2 I want the non NULL value to be the value
- In the case of #3 I want the values both used and delimited (e.g. using
Group_Concat(Acronym separator ";"0) - Where both values are the same I want to use that single value.
I have gotten this far with my Select statement, not sure how to expand the logic and/or to make it update:
Select Name,Acronym,ParentID,group_concat(ParentID separator ';') from TableA where Name in (
Select Name from TableA group by name having count(Name)>1) where group by name order by Name,Acronym
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
