-1

I've thousands of duplicate (ids) rows in SQL table but the other columns are different. I want to merge duplicate rows with respect to ids. Here is the sample.

Here is my table with duplicated rows.

id2     Name
50300   NAJMA BAIGUM
50300   MUHAMMAD IQBAL
50301   WAHABUDDIN
50301   ABDUL SALAM

What I want after merging into 1 row of corresponding duplicated id2 using sql query?

id2      Name       Name
50300   NAJMA BAIGUM    MUHAMMAD IQBAL
50301   WAHABUDDIN  ABDUL SALAM

Anyone can help me out?

jarlh
  • 42,561
  • 8
  • 45
  • 63

1 Answers1

0

How about array_agg and group_by ?

SELECT id2, array_agg(name) FROM mysterious_table GROUP BY id2
AnC
  • 641
  • 4
  • 16
  • No luck. showing an error "Msg 195, Level 15, State 10, Line 21 'array_agg' is not a recognized function name." – Munawar Khan Feb 28 '18 at 09:09
  • And have you tried the link from Tim Biegeleisen in the comments above ? – AnC Feb 28 '18 at 09:11
  • Tried, showing the error "Msg 195, Level 15, State 10, Line 24 'group_concat' is not a recognized function name." – Munawar Khan Feb 28 '18 at 09:19
  • yes i didn't recognize the sql-2000-server tag so array_agg is not present, which means there is no easy solution. please follow the link from Tim Biegeleisen to find a workaround – AnC Feb 28 '18 at 09:20
  • I've achieved this in Mysql after migration of rows from SQL Server 2000 to MySQL. – Munawar Khan Mar 01 '18 at 05:49