Re: SQL command join question

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Ehab Galal <ehabgalal123(at)hotmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: SQL command join question
Date: 2006-11-30 00:57:01
Message-ID: 20061129165123.D23412@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Broersma Jr 2006-11-30 00:57:18 Re: SQL command join question
Previous Message Phillip Smith 2006-11-30 00:46:14 Re: SQL command join question