Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: SQL command join question



> 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.



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group