Combining several rows

From: Matthias Nagl <pg(at)mnagl(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Combining several rows
Date: 2004-05-24 12:39:55
Message-ID: 200405241439.55764.pg@mnagl.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello List!

I would like to combine the contents of several rows of a subquery. After
several hours of search in the documentation and the internet I didn'T find a
solution and hope anyone can help. My problem:

Let's say I've got a table in the following form:

SELECT * FROM test;

id | name
-----------
1 | abc
2 | def
3 | ghi

For a table like this I am looking for a query that returns a result that
looks this way:

name
-------------
abc, def, ghi

It should work for any number of rows. I would like to Insert the returned
String (with a comma separated list of all name-fields in the test-table) in
the main-query ( SELECT (whatever is a solution) AS name, other, fields FROM
tables...).

Thanks in advance

Matthias Nagl

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mike Mascari 2004-05-24 13:10:15 Re: Combining several rows
Previous Message Brendan Jurd 2004-05-24 09:55:24 PL/pgSQL: FOUND not set by EXECUTE?