I have a issue where I need to combine a bunch of duplicate data. I’m starting with a table that was merged from two different sources. An example of the data would be:
aID, bID, value1, value2, value3, value4
The issue is that there are situations where aID match bID but only one of the other fields are filled in:
1, 1, samedata, null, null, 1
1, 1, samedata, red, null, null
1, 1, samedata, null, htmldata, null
I’m looking for a way to display the entire row of data but roll up all the values that are not null so that there is one line per matching id. I’ve been trying Group By and Group_Concat but haven’t found the secret sauce yet.
The 1 row I would want from the example above would be:
1, 1, samedata, red, htmldata, 1
Any ideas?
One trick is to use
MAXorMIN, since those will prefer a non-null value over a null one:(When I use
MAXfor this purpose, I usually include a comment noting this, since it’s not instantly obvious to the casual reader.)