X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 63B6A9FB2CD for ; Thu, 7 Sep 2006 11:26:43 -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 62188-08-3 for ; Thu, 7 Sep 2006 11:26:38 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id C526A9F9F66 for ; Thu, 7 Sep 2006 11:26:35 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 7BAA03525E; Thu, 7 Sep 2006 07:26:33 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 79D9E3525A; Thu, 7 Sep 2006 07:26:33 -0700 (PDT) Date: Thu, 7 Sep 2006 07:26:33 -0700 (PDT) From: Stephan Szabo To: Emi Lu Cc: pgsql-sql@postgresql.org Subject: Re: Is it possible to left join based on previous joins result In-Reply-To: <45001AF6.4020706@encs.concordia.ca> Message-ID: <20060907072131.J60412@megazone.bigpanda.com> References: <45001AF6.4020706@encs.concordia.ca> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.119 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200609/52 X-Sequence-Number: 26263 On Thu, 7 Sep 2006, Emi Lu wrote: > Hello, > > Is it possible to do something like: > > select ... > from t1 > inner join t2 ... > left join t2.colN > > When t1 inner join with t2 I got unique result for t2.colN( colN's value > is table name). > > Can I continue to left join with the column "colN" in table t2? No, in part because it'd have to actually evaluate the first join in order to even plan the remainder of the query. It might be possible to do something similar, albeit somewhat slowly, inside a set returning function, but you'd have to decide how to handle more than one row being returned from the first join even if the value is unique, is that one join against the table or multiple joins.