Skip site navigation (1) Skip section navigation (2)

Re: Multiple rows into one row

From: "Mike Ellsworth" <younicycle(at)gmail(dot)com>
To: Raimon <coder(at)montx(dot)com>
Cc: "PostgreSQL Novice" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Multiple rows into one row
Date: 2008-02-02 15:54:26
Message-ID: 219951fd0802020754r28b0cf3bpd31e378dc1c38ef@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
On Feb 2, 2008 10:13 AM, Raimon <coder(at)montx(dot)com> wrote:
> Hello,
>
> I can't find any reference in PostgreSQL documentation, if this is
> possible:
>
> I want to have some rows in one column, with the values separated for
> example by a comma.
>
> SELECT name FROM animals WHERE customer_id = '5'
>
> - cat
> - dog
> - turtle
>
> I would like to have this like this:
>
> - cat, dog, turtle
>
>
> So I could issue a SELECT like this:
>
> SELECT customer.name, (SELECT name FROM animals WHERE customer_id =
> customer.id) AS animals FROM customer
>
> name    animals
> ------- -----------
> Peter   dog,cat
> Lisa            turtle
> Anthony bird,elephant
>
> I could find info about PIVOT and some other extra functionalities
> from other databases like Oracle, SQL server, ...
>

I think, here: http://www.postgresql.org/docs/8.3/static/tablefunc.html

In response to

Responses

pgsql-novice by date

Next:From: A. KretschmerDate: 2008-02-02 16:04:36
Subject: Re: Multiple rows into one row
Previous:From: RaimonDate: 2008-02-02 15:13:20
Subject: Multiple rows into one row

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group