Re: "select c1, method(c2) group by c1" returns all values of c2 for c1

From: Peter Steinheuser <psteinheuser(at)myyearbook(dot)com>
To: emilu(at)encs(dot)concordia(dot)ca
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: "select c1, method(c2) group by c1" returns all values of c2 for c1
Date: 2011-02-08 19:43:23
Message-ID: AANLkTikuf1u-V8f1T9Qp5pk5xMnLZRBom9SwY-FZRRMx@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I'm not saying this is good or best but:

select distinct a.c1, array_to_string(array(select c2 from t1 as b where
b.c1 = a.c1),',')
from t1 as a;
c1 | array_to_string
----+-----------------
1 | val1,val2,val3
2 | val1
3 | val5,val6
(3 rows)

On Tue, Feb 8, 2011 at 2:35 PM, Emi Lu <emilu(at)encs(dot)concordia(dot)ca> wrote:

> Good afternoon,
>
> Is there a method to retrieve the following results:
>
> T1(c1 int, c2 varchar(128) )
> ---------------------------------
>
>
> (1, val1);
> (1, val2);
> (1, val3);
> (2, val1);
> (3, val5);
> (3, val6);
>
> select c1, method(c2)
> group by c1
>
> returns:
> ============
> 1, "val1, val2, val3"
> 2, "val1"
> 3, "val5, val6"
>
>
> Thanks a lot!
>
> --
> Lu Ying
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

--
Peter Steinheuser
psteinheuser(at)myyearbook(dot)com

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rolando Edwards 2011-02-08 19:51:37 Re: "select c1, method(c2) group by c1" returns all values of c2 for c1
Previous Message Pavel Stehule 2011-02-08 19:43:19 Re: "select c1, method(c2) group by c1" returns all values of c2 for c1