Re: SQL command join question - Mailing list pgsql-sql

From Richard Broersma Jr
Subject Re: SQL command join question
Date
Msg-id 458025.22989.qm@web31815.mail.mud.yahoo.com
Whole thread Raw
In response to SQL command join question  ("Ehab Galal" <ehabgalal123@hotmail.com>)
List pgsql-sql
> 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);  ^^  -- which one t or t1?

> I'm getting the following error message:
> ERROR:  invalid reference to FROM-clause entry for table "t1"
> HINT:  There is an entry for table "t1", but it cannot be referenced from 
> this part of the query.

I am not use if I am about to give to the correct advice, but here is what stands out at me:

when you specify an outer join, I believe that you have to specify whether it is a
(left|right|full).

Also you are using a "t" to alias the (t1 .. t2 on (...)).  First of all, I am not sure this is
good syntax, but if I am wrong I will have learned something new.  That aside, if it is legal
syntax, I don't believe that you can refer to any of it's enternal tables any more.  So (t1.c=...)
should really be (t.c=...).

this is what I expect would work:

select          *
from       t1
left outer join       t2
on    ((t1.a,t1.b) = (t2.a,t2.b))
left outer join       t3
on    (t1.c = t3.c)
;

Regards,

Richard Broersma Jr.


pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: SQL command join question
Next
From: Tom Lane
Date:
Subject: Re: SQL command join question