pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Correia, Carla <Carla.Correia@logicacmg.com>
Cc: 'pgsql-sql@postgresql.org' <pgsql-sql@postgresql.org>
Subject: Re: Complex outer joins?
Date: Mon, 24 Mar 2003 10:18:10 -0500
Message-ID: <12785.1048519090@sss.pgh.pa.us> (raw)
In-Reply-To: <0F232CC93A58D6119C1600B0D0799B8102338822@hamsrvmx03.logica.co.uk>
References: <0F232CC93A58D6119C1600B0D0799B8102338822@hamsrvmx03.logica.co.uk>

"Correia, Carla" <Carla.Correia@logicacmg.com> writes:
> Simplified example:
 
>  select G.SELID, G.TEXT, 
>  	L.ID as SELLEVELID , L.SELLEVEL, L.LEVELJOIN, L.LEVELTEXT,
>  	C.ID as KRITERIENFELDID, C.SELFLD
>   from  G,  L,  C 
>   where 
>  	and G.SELID = L.SELID (+) 
>  	and L.SELID = C.SELID (+) 
>  	and L.SELLEVEL = C.SELLEVEL (+) 
 
> How can i write this in Postgres?

One of the un-fun things about Oracle's nonstandard syntax is that you
can't easily tell what the join order is supposed to be.  (At least I
can't; anyone know how this will get interpreted?)

The SQL-standard way of writing this would presumably be either

    from G left join L on (G.SELID = L.SELID)
         left join C on (L.SELID = C.SELID and L.SELLEVEL = C.SELLEVEL)

or

    from G left join
         (L left join C on (L.SELID = C.SELID and L.SELLEVEL = C.SELLEVEL))
         on (G.SELID = L.SELID)

depending on which join you think ought to be done first.  It might be
that the results are the same in this case, but I'm not convinced of
that.  In general the results of outer joins definitely depend on join
order.

			regards, tom lane




view thread (14+ messages)  latest in thread

Message-ID: <12785.1048519090@sss.pgh.pa.us>
Permalink:  ../12785.1048519090@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/12785.1048519090@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, Carla.Correia@logicacmg.com
  Subject: Re: Complex outer joins?
  In-Reply-To: <12785.1048519090@sss.pgh.pa.us>

* 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