Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 333342E30CF for ; Wed, 5 Dec 2007 07:46:33 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 04885-07 for ; Wed, 5 Dec 2007 07:46:29 -0400 (AST) Received: from fetter.org (start.fetter.org [66.92.188.65]) by postgresql.org (Postfix) with ESMTP id 60EE62E2F55 for ; Wed, 5 Dec 2007 07:46:28 -0400 (AST) Received: by fetter.org (Postfix, from userid 500) id 3FBD2FBC991; Wed, 5 Dec 2007 03:46:26 -0800 (PST) Date: Wed, 5 Dec 2007 03:46:26 -0800 From: David Fetter To: Ashish Karalkar Cc: pgsql-general@postgresql.org, ashish.karalkar@netcore.co.in Subject: Re: SQL Query Message-ID: <20071205114626.GB27030@fetter.org> References: <843803.85383.qm@web94301.mail.in2.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <843803.85383.qm@web94301.mail.in2.yahoo.com> User-Agent: Mutt/1.5.17 (2007-11-01) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/247 X-Sequence-Number: 124991 On Wed, Dec 05, 2007 at 10:24:04AM +0000, Ashish Karalkar wrote: > Hello List member, > > Iha a table containing two columns x and y . for single value of x there are multiple values in y e.g > > X Y > ------------ > 1 ABC > 2 PQR > 3 XYZ > 4 LMN > 1 LMN > 2 XYZ > > I want a query that will give me following output > > 1 ABC:LMN > 2 PQR:XYZ > 3 XYZ > 4 LMN > > Any help will be really helpful Use the array_accum aggregate from the docs as follows: SELECT x, array_to_string(array_accum(y),':') FROM your_table GROUP BY x; Cheers, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fetter@gmail.com Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate