troubleshooting Question

SQL Combine Rows into one row

Avatar of johnnyg123
johnnyg123Flag for United States of America asked on
Microsoft SQL Server
3 Comments1 Solution22 ViewsLast Modified:
Here is some sample data from the Orders table (Sql server 2014)
Note: There is not a set number of product and producttype combinations.  It grows constantly

OrderId Product           ProductType
1            TV                  Electronics
1            Jeans             Clothes
1            Dresser          Furniture
2            Monopoly       Board Games
2            Socks             Clothes

I would like to combine all entries for the same order number into a single row

using the sample data I would like the query to return the following

OrderID  Product1           ProductType1  Product2   ProductType2    Product3  Product3  
1              TV                    Electronics       Jeans       Clothes              Dresser    Furniture
2              Monopoly         Board Games   Socks      Clothes
Andrei Fomitchev

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros