Skip to content
Advertisement

how to merge multiple rows into single in MSSQL

this is my data: enter image description here

id segment country product status month year

83916512 Government Null Null Null Null 2014 83916512 Null Germany Null Null Null 2014 83916512 Null Null Carretera Null Null 2014 83916512 Null Null Null completed Null 2014 83916512 Null Null Null Null June 2014 83916512 Null Null Null Null Null 2014

i want below output enter image description here

can anybody help me out to achieve this please 🙂

Advertisement

Answer

You can use following SQL Select

select
    id,
    MAX(segment) as segment,
    MAX(country) as country,
    MAX(product) as product,
    MAX(status) as status,
    MAX(month) as month,
    MAX(year) as year
from tbl
group by id
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement