0

I have a scenario where In my table there are lots of duplicate value. lets's say.

SID|LOTID|TEST
1    45    A
1    45    B
1    45    C

I want a mysql query which can provide me output like this.

SID|LOTID|TEST
1    45    A,B,C
Vamsi Prabhala
  • 48,685
  • 4
  • 36
  • 58
Prateek Bhati
  • 25
  • 1
  • 8

1 Answers1

0

Please try the below code. This is working fine with SQL Server 2012

DECLARE @Table TABLE (SID int, LOTID int, TEST CHAR(2))
INSERT INTO @Table
(SID,LOTID,TEST)
VALUES

(1,45,'A'),
(1,45,'B'),
(1,45,'C') 

SELECT SID,LOTID, TEST = 
    STUFF((SELECT ', ' + TEST
           FROM @Table b 
           WHERE b.SID = a.SID 
          FOR XML PATH('')), 1, 2, '')
FROM @Table a
GROUP BY SID,LOTID
Praveen ND
  • 540
  • 2
  • 10