Home > Software engineering >  Merge multiple rows for each ID so that the most information is collected
Merge multiple rows for each ID so that the most information is collected

Time:01-31

I have multiple rows for each ID, I don't want the most recent, I would like to merge these into the most complete entry for each ID. Each ID may have a different number of associated rows. I'd like to do this in either Alteryx or SQL but not sure at all where to begin.

for example:

row    ID                 ColA         ColB        ColC
 1    1234                             red         
 2    1234               purple        red        
 3    1234                                          blue

Desired result:

row    ID            ColA      ColB      ColC
1      1234        Purple      red       blue

CodePudding user response:

It looks like a simple aggregation should do the trick.

For Example

Select row = min(row)
      ,ID
      ,ColA = max(ColA)
      ,ColB = max(ColB) 
      ,ColC = max(ColC)
 From  YourTable
 Group By ID
  • Related