Sql-server – SQL Server : I need to combine multiple rows into one row with different column values

sql server

I have a view

Order          Drink       Entree         Desert  
--------------------------------------------------
12             Null        Preparing      Null  
12             Ready       NULL           NULL   
12             NULL        NULL           Waiting  

I want to convert it to:

Order          Drink       Entree         Desert  
---------------------------------------------------
12             Ready       Preparing      Waiting  

Best Answer

You can use an appropriate aggregation function. In this case, it seems like MIN or MAX will do the trick:

SELECT Order,
       MIN(Drink) Drink,
       MIN(Entree) Entree,
       MIN(Desert) Desert
FROM dbo.YourTable
GROUP BY Order;