pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Denis <sqllist@coralindia.com>
To: pgsql-sql@postgresql.org
Subject: Re: Left joins with multiple tables
Date: Mon, 19 Jan 2004 10:28:01 +0530
Message-ID: <009b01c3de48$d379eae0$0f32a8c0@denisnew> (raw)
References: <pan.2004.01.17.02.29.56.311442@cfconsulting.ca>


Hi Colin,

Try

select id, name, a.field1, b.field2, c.field3
from
 people p left outer join a on (a.person_id = p id)
              left outer join b on (b.person_id = p.id)
              left outer join c on (c.person_id = p.id);

HTH

Denis


----- Original Message ----- 
From: "Colin Fox" <cfox@cfconsulting.ca>
To: <pgsql-sql@postgresql.org>
Sent: Saturday, January 17, 2004 8:00 AM
Subject: [SQL] Left joins with multiple tables


> Hi, all.
> 
> I've got a bit of a problem here. I have 4 tables - people, a, b, c (not
> the original names).
> 
> For each person in the people table, they may or may not have a record in
> a, may or may not have a record in b, and may or may not have a record in
> c.
> 
> Handling the first table (a) is easy:
> 
> select id, name
> from people p left outer join a on a.person_id = p id;
> 
> But I'd like to be able to do something like:
> 
> select
>     id, name, a.field1, b.field2, c.field3
> from
>     people p left outer join a on a.person_id = p id,
>     people p left outer join b on b.person_id = p.id,
>     people p left outer join c on c.person_id = p.id;
> 
> Naturally you can't repeat the 'people p' clause 3 times, but is there
> some other syntax that would let me do this?
> 
> Thanks!
>   cf
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster




view thread (3+ messages)

Message-ID: <009b01c3de48$d379eae0$0f32a8c0@denisnew>
Permalink:  ../009b01c3de48$d379eae0$0f32a8c0@denisnew/
Also on:    postgresql.org/message-id/009b01c3de48$d379eae0$0f32a8c0@denisnew

 · 

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: sqllist@coralindia.com
  Subject: Re: Left joins with multiple tables
  In-Reply-To: <009b01c3de48$d379eae0$0f32a8c0@denisnew>

* 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