Tarak Tarak - 1 month ago 7
SQL Question

SQL - Merge records by ID field

I have a select statement where I get

ProductID Gender Color Type AgeRange
344842 Boys NULL NULL NULL
344842 NULL Black NULL NULL
344842 NULL NULL Leggings NULL
344842 NULL NULL NULL 2 to 4 Years


I wish to get merged row like this

ProductID Gender Color Type AgeRange
344842 Boys Black Leggings 2 to 4 Years

Answer
select 
productid, max(Gender) as Gender, 
max(Color) as Color, max(Type) as Type, max(AgeRange) as AgeRange
from
table
group by 
productid