Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id F0F89475EBB for ; Wed, 23 Oct 2002 10:47:39 -0400 (EDT) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by postgresql.org (Postfix) with ESMTP id 3CA13475AAC for ; Wed, 23 Oct 2002 10:47:39 -0400 (EDT) Received: from klaster.net (pj106.krakow.cvx.ppp.tpnet.pl [217.99.210.106]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 8EC862B4D8; Wed, 23 Oct 2002 16:41:04 +0200 (CEST) Message-ID: <3DB6B7F7.2030609@klaster.net> Date: Wed, 23 Oct 2002 16:53:43 +0200 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; PL; rv:1.1) Gecko/20020826 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: Stephan Szabo Cc: pgsql-sql@postgresql.org Subject: Re: sub-select with aggregate References: <20021023071418.N4419-100000@megazone23.bigpanda.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/297 X-Sequence-Number: 10014 Uz.ytkownik Stephan Szabo napisa?: > But you can't do that anyway, because you don't expose group_id > in the original query. I assume user_id was a mistake then and was > meant to be group_id or that both were meant to be in the > select list. Yes, I meant group_id, but in orginal query I didn't have to add group_id to select list. > In the first case changing the order means that the output > group_id column is X.group_id rather than users.group_id > (using removes one of them which is why group_id isn't > ambiguous. In the second it uses on to get both group_ids > and exposes the one from X. The problem isn't ambigous columns, but speed. I think Postgres first performs sub-query with all records from table (it takes very long time). After this Postgres permforms joining table with sub-query. The question is: How to speed up query like this? How to give param group_id from first table (users) to subquery? Tomasz Myrta