Question: I have two shape files (e.g. postal code areas and cities) which I want to join based on an id that both shape files have in common (the id would be the city name in this example). Joining the two tables is not the problem (via Join and selecting the city name as field on which the join is based).

But what I really want is an enumeration of all the postal codes of a city - if I join them and take cities with postal codes, every city will get one random postal code that has the same city name as the city, but I want all of them as comma-separated list as new attribute in the cities shape file).

Is there a way to do that?

Example table postal codes:

```

Postal Code | City
          0 | A-Town     
          1 | A-Town     
          2 | A-Town     
          3 | B-Town     
          4 | B-Town     
          5 | C-Town     

```

Example cities table:

```

City Name
   A-Town
   B-Town
   C-Town     

```

Desired outcome table:

```

City Name | Postal codes
   A-Town | 0, 1, 2
   B-Town | 3, 4
   C-Town | 5

```

Answer: 
I remembered [an entry](http://blogs.esri.com/esri/arcgis/2012/07/05/concatenaterowvalues/) from ESRI's Geoprocessing blog which describes a [tool](http://www.arcgis.com/home/item.html?id=52dfcef46fdb4c76bfbc08dc01570f3c) which concatenates row values and does what you're after.

I haven't used it before as I haven't had a need for it yet. But I thought it looked useful and I think this will be an easy solution for you.

From the [ArcGIS Resource Center](http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=F3368746-1422-2418-A061-D00793D7F9F0):

> 
> This tool is based on a python script that takes an input table,
>  selects a set of rows based on a field value and concatenates the row
>  values for a specified field. This tool does not create a new output,
>  but updates the input data.
> 
> 
>
Please don't think that you can or should do this in DML. Doing so is not only painful for you and your systems, but it is excruciating to watch as a third-party.

Your options are limited to either scripting, writing an extension or using a pivot table. While ESRI has a [pivot table](http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//0017000000n8000000) function, excel's is much easier to use and manage.

Below is an simple example for how you can script the output you require in C#. It can be quite easily converted to python.

```
Dictionary<String, List<String>> output = new Dictionary<string, List<string>>();
foreach (var row in table.rows) // Not sure what data structure you're working with.
{
  if (!output.ContainsKey(row.city))
  {
    output.Add(city, new List<string>());
  }
  output[city].Add(row.postcode);
}

String rowTemplate = "\"{0}\", \"{1}\";";
StringBuilder sb = new StringBuilder();
sb.AppendLine(String.Format(rowTemplate, "City", "Postcodes");
foreach (var row in output)
{
  sb.AppendLine(String.Format(rowTemplate, row.Key, String.Join(", ", row.Value.ToArray())));
}
String report = sb.ToString();

```