pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Colin Fox <cfox@cfconsulting.ca>
To: pgsql-sql@postgresql.org
Subject: Left joins with multiple tables
Date: Sat, 17 Jan 2004 02:30:01 GMT
Message-ID: <pan.2004.01.17.02.29.56.311442@cfconsulting.ca> (raw)

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





view thread (3+ messages)  latest in thread

Message-ID: <pan.2004.01.17.02.29.56.311442@cfconsulting.ca>
Permalink:  ../pan.2004.01.17.02.29.56.311442@cfconsulting.ca/
Also on:    postgresql.org/message-id/pan.2004.01.17.02.29.56.311442@cfconsulting.ca

 · 

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: cfox@cfconsulting.ca
  Subject: Re: Left joins with multiple tables
  In-Reply-To: <pan.2004.01.17.02.29.56.311442@cfconsulting.ca>

* 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