<p>I am looking for a way to concatenate the strings of a field within a group by query. So for example, I have a table:</p>

<pre><code>ID   COMPANY_ID   EMPLOYEE
1    1            Anna
2    1            Bill
3    2            Carol
4    2            Dave
</code></pre>

<p>and I wanted to group by company_id to get something like:</p>

<pre><code>COMPANY_ID   EMPLOYEE
1            Anna, Bill
2            Carol, Dave
</code></pre>

<p>There is a built-in function in mySQL to do this <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat" rel="noreferrer">group_concat</a></p>

I claim no credit for the answer because I found it after some searching:
What I didn't know is that PostgreSQL allows you to define your own aggregate functions with
CREATE AGGREGATE
This post
on the PostgreSQL list shows how trivial it is to create a function to do what's required:
```
```
CREATE AGGREGATE textcat_all(
  basetype    = text,
  sfunc       = textcat,
  stype       = text,
  initcond    = ''
);

SELECT company_id, textcat_all(employee || ', ')
FROM mytable
GROUP BY company_id;
```
```