0

How to get result from database with multiple values to the same id separated by comma....

please help with this..

thank you

Id     |    Code
----------------------
0001   |   IN,ON,ME,OH
0002   |   ON,VI,AC,ZO
0003   |   QA,PS,OO,ME
marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
user1208177
  • 5
  • 1
  • 2
  • 6
  • **WHAT** database system do you use - and which version?? *SQL* = Structured Query Language - the query language used by **many** database systems - that doesn't really say much at all. Things like this can be very vendor-specific - so we **need to know** what concrete database system you're using ..... – marc_s Jul 01 '12 at 16:45
  • If you're ussing SQL-SERVER, possible answer here: http://stackoverflow.com/questions/8868604/sql-group-concat-function-in-sql-server – Gonzalo.- Jul 01 '12 at 19:41

1 Answers1

0

Assuming you are using MySQL:

SELECT 
Id,
GROUP_CONCAT(Code SEPARATOR ',')
FROM
yourTable
GROUP BY Id

Here you can find further information.

fancyPants
  • 49,071
  • 32
  • 84
  • 94