Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id D70019FB21D for ; Wed, 29 Nov 2006 20:57:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 21629-07 for ; Wed, 29 Nov 2006 20:56:54 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id F11059FB1CF for ; Wed, 29 Nov 2006 20:57:04 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 3BE8135355; Wed, 29 Nov 2006 16:57:01 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 39EB335352; Wed, 29 Nov 2006 16:57:01 -0800 (PST) Date: Wed, 29 Nov 2006 16:57:01 -0800 (PST) From: Stephan Szabo To: Ehab Galal Cc: pgsql-sql@postgresql.org Subject: Re: SQL command join question In-Reply-To: Message-ID: <20061129165123.D23412@megazone.bigpanda.com> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/283 X-Sequence-Number: 26935 On Wed, 29 Nov 2006, Ehab Galal wrote: > I have three tables t1(a, b, c, d), t2(a, b, c, k), and t3(c, e). I need to > outer join them as shown below, but only have all tuples from t1 as output. > But the following syntax does not allow me to do so. > > SELECT t1.* > FROM (t1 outer join t2 on (t1.a=t2.a and t1.b=t2.b)) t outer join t3 on > (t1.c=t3.c); I think you don't want to alias the output of the t1/t2 join to t if you're planning to continue referring to t1 in the rest of the query since I think the alias is going to hide the original t1 name. I'm not sure which outer join you were trying to use, but assuming left for now, I think something like SELECT t1.* FROM t1 left outer join t2 on (t1.a=t2.a and t1.b=t2.b ) left outer join t3 on (t1.c=t3.c); might work for you.