Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 19DDD1337B8A for ; Tue, 8 Feb 2011 16:09:40 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 08881-04 for ; Tue, 8 Feb 2011 20:09:33 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from oldperseverance.encs.concordia.ca (oldperseverance.encs.concordia.ca [132.205.96.94]) by mail.postgresql.org (Postfix) with ESMTP id 29C031337BA3 for ; Tue, 8 Feb 2011 16:09:32 -0400 (AST) Received: from cacao.encs.concordia.ca (emilu@cacao.encs.concordia.ca [132.205.47.225]) by oldperseverance.encs.concordia.ca (envelope-from emilu@encs.concordia.ca) (8.13.7/8.13.7) with ESMTP id p18K9TS0019447; Tue, 8 Feb 2011 15:09:29 -0500 Message-ID: <4D51A2F9.1010809@encs.concordia.ca> Date: Tue, 08 Feb 2011 15:09:29 -0500 From: Emi Lu Reply-To: emilu@encs.concordia.ca User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20101125 Lightning/1.0b1 Thunderbird/3.0.11 MIME-Version: 1.0 To: Rolando Edwards CC: "pgsql-sql@postgresql.org" Subject: Re: "select c1, method(c2) group by c1" returns all values of c2 for c1 References: <4D519B0A.9040708@encs.concordia.ca> <0ED65673FA8E634AAB252741A6CD3B5E0E7CFE3B26@lw-exchange4b.us.logicworks.net> In-Reply-To: <0ED65673FA8E634AAB252741A6CD3B5E0E7CFE3B26@lw-exchange4b.us.logicworks.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.58 on oldperseverance.encs.concordia.ca at 2011/02/08 15:09:29 EST X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/41 X-Sequence-Number: 35117 On 02/08/2011 02:51 PM, Rolando Edwards wrote: > SELECT distinct c1,array_to_string(array(SELECT c2 FROM T1 B where A.c1=B.c1),', ') from T1 A order by c1; > > Give it a Try !!! Thanks a lot! Very helpful! array_to_string() + array() is exactly what I am looking for! I just wonder that array_to_string() + array() will provide me good performance, right? If the calculation will be based on millions records. Thanks again! -- Lu Ying > Rolando A. Edwards > MySQL DBA (SCMDBA) > > 155 Avenue of the Americas, Fifth Floor > New York, NY 10013 > 212-625-5307 (Work) > 201-660-3221 (Cell) > AIM& Skype : RolandoLogicWorx > redwards@logicworks.net > http://www.linkedin.com/in/rolandoedwards > > > -----Original Message----- > From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Emi Lu > Sent: Tuesday, February 08, 2011 2:36 PM > To: pgsql-sql@postgresql.org > Subject: [SQL] "select c1, method(c2) group by c1" returns all values of c2 for c1 > > 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 > -- Emi Lu, ENCS, Concordia University, Montreal H3G 1M8 emilu@encs.concordia.ca +1 514 848-2424 x5884