Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 79EA06333C6 for ; Tue, 15 Sep 2009 04:56:21 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 90971-03 for ; Tue, 15 Sep 2009 07:56:06 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.186]) by mail.postgresql.org (Postfix) with ESMTP id A726363315A for ; Tue, 15 Sep 2009 04:56:10 -0300 (ADT) Received: from webserv.wug.de ([194.25.154.138]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0MKv5w-1MnStS0vSq-000egP; Tue, 15 Sep 2009 09:56:07 +0200 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1MnStR-00059W-00 for pgsql-sql@postgresql.org; Tue, 15 Sep 2009 09:56:05 +0200 Date: Tue, 15 Sep 2009 09:56:05 +0200 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: ordered by join? ranked aggregate? how to? Message-ID: <20090915075605.GB8046@a-kretschmer.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-OS: Debian/GNU Linux - weil ich es mir Wert bin! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX18vEAT6FnF06I0EPJbJwaab4SjUf4kyJDRtHnP OH6KJqADy1QshnU4POdgR8KWjC47SuOV0m0oSB3ggUV8JGIX0h gYb5tQLA/ZuGGoDh4AfEw== X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.279 tagged_above=-10 required=5 tests=AWL=0.320, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200909/64 X-Sequence-Number: 33129 In response to wstrzalka : > What I need is to join 2 tables > > CREATE TABLE master( > id INT4 > ); > > > CREATE TABLE slave ( > master_id INT4, > rank INT4, > value TEXT); > > > What I need is to make the query: > > SELECT m.id, array_agg(s.value) AS my_problematic_array > FROM master AS m LEFT JOIN slave AS s ON (m.id = s.master_id) > GROUP BY m.id; Faster solution (compared to my other email): test=# select id, array_agg(value) from (SELECT m.id, s.value FROM master AS m LEFT JOIN slave AS s ON (m.id = s.master_id) order by 1,2) foo group by 1; id | array_agg ----+----------- 1 | {3,5,7} 2 | {NULL} (2 rows) Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)