Avatar of johnnyg123
johnnyg123Flag for United States of America

asked on 

SQL Combine Rows into one row

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
Microsoft SQL Server

Avatar of undefined
Last Comment
johnnyg123
Avatar of Sharath S
Sharath S
Flag of United States of America image

ASKER CERTIFIED SOLUTION
Avatar of Andrei Fomitchev
Andrei Fomitchev
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of johnnyg123
johnnyg123
Flag of United States of America image

ASKER

thanks for the responses.

I marked Andrei's as the solution since his response took into account the sample data I posted


Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo