Skip to content
Advertisement

How to merge many rows with the same ID with SQL Server

I need the help from the community to solve the following problem that I found (I’m using SQL Server):

I have two tables, USER and INFO.

USER:

INFO:

I want to merge the info table per user in one row as follows:

I’ve been trying many options and also surfing through stackoverflow posts, but without any results to my situation.

Thanks in advance!

Kind regards,

Aovon.

Advertisement

Answer

If you are sure that there will be only 3 phones and emails then following query will work:

Sample code here..

Use dynamic query for pivoting as:

Sample code here..

Hope this helps!!!

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement