X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7897055BBC for ; Thu, 24 Feb 2005 08:21:58 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 35739-03 for ; Thu, 24 Feb 2005 08:21:53 +0000 (GMT) Received: from anchor-post-32.mail.demon.net (anchor-post-32.mail.demon.net [194.217.242.90]) by svr1.postgresql.org (Postfix) with ESMTP id 159A455B8B for ; Thu, 24 Feb 2005 08:21:52 +0000 (GMT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-32.mail.demon.net with esmtp (Exim 4.42) id 1D4EFz-000GYs-7j; Thu, 24 Feb 2005 08:21:59 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 8BA3815D10; Thu, 24 Feb 2005 08:21:58 +0000 (GMT) Message-ID: <421D8EA6.7020107@archonet.com> Date: Thu, 24 Feb 2005 08:21:58 +0000 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Kai Hessing Cc: pgsql-sql@postgresql.org Subject: Re: Advanced SELECT References: <383fk1F5hq3hhU1@individual.net> In-Reply-To: <383fk1F5hq3hhU1@individual.net> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.063 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200502/295 X-Sequence-Number: 20405 Kai Hessing wrote: > > The normal clause would look like: > > SELECT c.companyname, s.sectorname FROM company c, sector s, > company_sector cs WHERE cs.cid = c.cid AND cs.sid = s.sid ORDER BY > c.companyname; > c.companyname | ??? (sectors) > ---------------+------------------------ > company1 | sectora, sectorb > company2 | sectora, sectorb, sectorc > company3 | sectora > company4 | sectorc > Search the mailing-list archives for "custom aggregate concat" and you'll quickly find an example of how to write your own custom aggregate (like SUM()). Warning - I don't think you can guarantee the order of elements in the aggregated sectors. -- Richard Huxton Archonet Ltd