0

Possible Duplicate:
Sql select group by and string concat

My SQL table looks like this:

City_Code        Post_Code   Post_Code_Description
100               A1          ABC
100               C8          XYZ
100               Z3          MNO
200               D4          LMN
300               E3          IJK
300               B9          RST

It's a mapping between city_code and Post_Code. One City_Code can have many Post Codes. Now I want to run a query to get something like this:

City_Code           Post_Code         Post_Code_Description
100                 A1,C8,Z3          ABC,XYZ,MNO
200                 D4                LMN
300                 E3,B9             IJK,RST

Can you please help me with this?

Community
  • 1
  • 1
  • if you're using SQL Server, there are a number of suggestions here: http://stackoverflow.com/questions/5996177/output-a-comma-seperated-list-in-t-sql – paul Oct 01 '12 at 09:16
  • http://stackoverflow.com/questions/5196371/sql-query-concatenating-results-into-one-string – Mitch Wheat Oct 01 '12 at 09:16
  • 1
    *Why* do you want a field with comma separated values? What do you intend to do with it? – podiluska Oct 01 '12 at 09:18
  • 2
    @podiluska: that's not an unusual requirement for display purposes (think reports or an overview) –  Oct 01 '12 at 09:48

0 Answers0