pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Broersma Jr <rabroersma@yahoo.com>
To: Ehab Galal <ehabgalal123@hotmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: SQL command join question
Date: Wed, 29 Nov 2006 16:57:18 -0800 (PST)
Message-ID: <458025.22989.qm@web31815.mail.mud.yahoo.com> (raw)
In-Reply-To: <BAY24-F23D89B0EEF2CFB0C611FFA96DB0@phx.gbl>

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



view thread (5+ messages)  latest in thread

Message-ID: <458025.22989.qm@web31815.mail.mud.yahoo.com>
Permalink:  ../458025.22989.qm@web31815.mail.mud.yahoo.com/
Also on:    postgresql.org/message-id/458025.22989.qm@web31815.mail.mud.yahoo.com

 · 

reply

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: rabroersma@yahoo.com, ehabgalal123@hotmail.com
  Subject: Re: SQL command join question
  In-Reply-To: <458025.22989.qm@web31815.mail.mud.yahoo.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