X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 04D849FB1F0 for ; Tue, 2 May 2006 18:16:18 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 53655-05 for ; Tue, 2 May 2006 18:16:06 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from fep01.ttnet.net.tr (mail.ttnet.net.tr [212.175.13.129]) by postgresql.org (Postfix) with ESMTP id 5EDE69FB1D3 for ; Tue, 2 May 2006 18:16:04 -0300 (ADT) Received: from alamut ([85.102.236.143]) by fep01.ttnet.net.tr with ESMTP id <20060502211602.TOEG11882.fep01.ttnet.net.tr@alamut>; Wed, 3 May 2006 00:16:02 +0300 Date: Wed, 3 May 2006 00:13:40 +0300 From: Volkan YAZICI To: Everton =?iso-8859-1?Q?Lu=EDs?= Berz Cc: pgsql-sql@postgresql.org Subject: Re: Sorting aggregate column contents Message-ID: <20060502211340.GA188@alamut> References: <4457C86F.8040303@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4457C86F.8040303@gmail.com> User-Agent: Mutt/1.4.2.1i X-NAI-Spam-Rules: 0 Rules triggered X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/17 X-Sequence-Number: 25048 On May 02 06:00, Everton Luís Berz wrote: > Is it possible to sort the content of an aggregate text column? > > Query: > select s.name, ag_concat(c.name) from state s > inner join city c on (c.idstate = s.idstate) > group by s.name > order by s.name; IMHO, you can receive results ordered by using a subselect: SELECT T.s_name, ag_concat(T.c_name) FROM (SELECT s.name, c.name FROM state AS s INNER JOIN city AS c ON (c.idstate = s.idstate) ORDER BY s.name, c.name) AS T (s_name, c_name) GROUP BY T.s_name; Regards.