X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 40BF5D1E816 for ; Mon, 19 Jan 2004 04:57:19 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 17027-06 for ; Mon, 19 Jan 2004 00:56:48 -0400 (AST) Received: from ns.tirupati.biz (unknown [64.239.5.38]) by svr1.postgresql.org (Postfix) with SMTP id B3379D1E821 for ; Mon, 19 Jan 2004 00:56:46 -0400 (AST) Received: (qmail 27187 invoked from network); 19 Jan 2004 05:55:38 -0000 Received: from softdnserror (HELO server2k) (61.11.69.95) by ns.tirupati.biz with SMTP; 19 Jan 2004 05:55:38 -0000 Received: from 192.168.50.15 by server2k ([192.168.50.102] running VPOP3) with SMTP for ; Mon, 19 Jan 2004 10:32:12 +0530 X-MSReally-From: sqllist@coralindia.com Message-ID: <009b01c3de48$d379eae0$0f32a8c0@denisnew> From: "Denis" To: References: Subject: Re: Left joins with multiple tables Date: Mon, 19 Jan 2004 10:28:01 +0530 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Server: VPOP3 V1.5.0 - Registered X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=4.7 tagged_above=0.0 required=5.0 tests=QUOTED_EMAIL_TEXT, RCVD_IN_DSBL, RCVD_IN_NJABL, REFERENCES X-Spam-Level: **** X-Archive-Number: 200401/161 X-Sequence-Number: 16554 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" To: 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