From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Ehab Galal <ehabgalal123@hotmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: SQL command join question
Date: Wed, 29 Nov 2006 16:57:01 -0800 (PST)
Message-ID: <20061129165123.D23412@megazone.bigpanda.com> (raw)
In-Reply-To: <BAY24-F23D89B0EEF2CFB0C611FFA96DB0@phx.gbl>
References: <BAY24-F23D89B0EEF2CFB0C611FFA96DB0@phx.gbl>
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sszabo@megazone.bigpanda.com, ehabgalal123@hotmail.com
Subject: Re: SQL command join question
In-Reply-To: <20061129165123.D23412@megazone.bigpanda.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox