Re: Left joins with multiple tables

Поиск
Список
Период
Сортировка
От Denis
Тема Re: Left joins with multiple tables
Дата
Msg-id 009b01c3de48$d379eae0$0f32a8c0@denisnew
обсуждение исходный текст
Ответ на Left joins with multiple tables  (Colin Fox <cfox@cfconsulting.ca>)
Список pgsql-sql
Hi Colin,

Try

select id, name, a.field1, b.field2, c.field3
frompeople 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



В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: help with limiting query results
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Execute permissions for stored functions