Sql-server – how can I convert multiple rows into one row

querysql server

Imagine I have a table like this:

---------------------------------------------
Name | Property_1 | Property_2 | Property_3  |
---------------------------------------------
jimi | tall       | null       | null        |
---------------------------------------------
jimi | null       | black      | null        |
---------------------------------------------
jimi | null       | null       |  African    |
----------------------------------------------

I want to convert that to this table:

------------------------------------------------
Name | Property_1  |  property_2   | Property_3 |
------------------------------------------------
jimi | tall        | black         |African     |
-------------------------------------------------

how can I achieve that in MSSQL database?

Best Answer

while other values of a column are NULL, easily you can use this query:

SELECT Name,MAX(property_1),MAX(property_2),MAX(property_3)
FROM YourTable
GROUP BY Name