My SQL table is like following
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 has many Post Codes. Now i want to run a Query to get something like following
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 thisy SQL table is like following
Use a recursive query for this:
try this:
try this:
If you are using MySQL you can use
GROUP_CONCAT()
For SQL Server you can use
STUFF()
andFOR XML PATH()