pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dmitri Bichko <dbichko@aveopharma.com>
To: Lane Van Ingen <lvaningen@esncc.com>
To: pgsql-sql@postgresql.org
Subject: Re: Is it This Join Condition Do-Able?
Date: Wed, 17 Aug 2005 13:25:53 -0400
Message-ID: <F18A6F7CF1661F46920F2CF713122FED46CC69@mail.aveo.aveopharma.com> (raw)

How about:

SELECT a.keyfld, a.foo1, b.foo2, c.foo3
FROM a
LEFT JOIN b USING(keyfld)
LEFT JOIN c USING(keyfld)

Dmitri

> -----Original Message-----
> From: pgsql-sql-owner@postgresql.org 
> [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Lane Van Ingen
> Sent: Wednesday, August 17, 2005 12:55 PM
> To: pgsql-sql@postgresql.org
> Subject: [SQL] Is it This Join Condition Do-Able? 
> 
> 
> Given three tables: a, b, c ; each consist of a 'keyfld' and 
> a field called
> 'foo':
>      tbl a       tbl b         tbl c
>    ---------   ---------     ---------
>    a.keyfld    b.keyfld       c.keyfld
>    a.foo1      b.foo2         c.foo3
> 
> I want to always return all of tbl a; and I want to return 
> b.foo2 and c.foo3 if they can be joined to based on keyfld.a; 
> I know that it will involve a LEFT OUTER JOIN on table a, but 
> have not seen any examples of joins like this on 3 or more tables.
> 
> select a.keyfld, a.foo1, b.foo2, c.foo3
> from a, b, c
> where a.keyfld = <some value>
> and   a.keyfld = b.keyfld
> and   a.keyfld = c.keyfld;
> 
> Results could look like this:
>   a.keyfld  a.foo1   b.foo2  c.foo3
>     xxxx     xxxx     xxxx    (null)
>     xxxx     xxxx    (null)    xxxx
>     xxxx     xxxx    (null)   (null)
>     xxxx     xxxx     xxxx     xxxx
> 
> 
> 
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>        choose an index scan if your joining column's datatypes do not
>        match
> 
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer



view thread (7+ messages)  latest in thread

Message-ID: <F18A6F7CF1661F46920F2CF713122FED46CC69@mail.aveo.aveopharma.com>
Permalink:  ../F18A6F7CF1661F46920F2CF713122FED46CC69@mail.aveo.aveopharma.com/
Also on:    postgresql.org/message-id/F18A6F7CF1661F46920F2CF713122FED46CC69@mail.aveo.aveopharma.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: dbichko@aveopharma.com, lvaningen@esncc.com
  Subject: Re: Is it This Join Condition Do-Able?
  In-Reply-To: <F18A6F7CF1661F46920F2CF713122FED46CC69@mail.aveo.aveopharma.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