Grouping SQL

Abdul Khan
Abdul Khan used Ask the Experts™
on
I need to see each customer in one row, in other words all items related to a customer should be in one row group by Cust# , please help. Thanks.

Cust#         Customer      age      Item1      Item2      Item3       Item4
123                  John               50          tea                  
456                 Smith               40                    apple            
789                  Tom              35                                                  milk
123                  John               50                                  orange      
123                 John              50                   apple            
789                Tom               35                                orange      
456               Smith              40         tea                  
123      John                      50                                                    milk
Capture.PNG
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
SQL Server DBA & Architect, EE Solution Guide
Awarded 2009
Distinguished Expert 2018
Commented:
Simple approach would be to use GROUP BY..
SELECT Cust#, Customer, age, MAX(Item1) Item1, MAX(Item2) Item2, MAX(Item3) Item3, MAX(Item4) Item4
FROM ur_table
GROUP BY Cust#, Customer, age

Open in new window

Author

Commented:
Thanks so much Raja!!
Raja Jegan RSQL Server DBA & Architect, EE Solution Guide
Awarded 2009
Distinguished Expert 2018

Commented:
Welcome, glad to assist..

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial