X-Original-To: pgsql-sql@postgresql.org Received: from localhost (unknown [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 287FF925076 for ; Tue, 20 May 2003 12:36:54 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193:10024]) (amavisd-new) with ESMTP id 13741-10 for ; Tue, 20 May 2003 12:36:44 -0400 (EDT) Received: from anchor-post-32.mail.demon.net (anchor-post-32.mail.demon.net [194.217.242.90]) by developer.postgresql.org (Postfix) with ESMTP id EF549924FE9 for ; Tue, 20 May 2003 12:36:43 -0400 (EDT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-32.mail.demon.net with esmtp (Exim 3.35 #1) id 19IA6U-0006Mt-0W; Tue, 20 May 2003 17:36:42 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 8661316A52; Tue, 20 May 2003 17:36:41 +0100 (BST) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id D933016A51; Tue, 20 May 2003 17:36:40 +0100 (BST) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: ww zz , pgsql-sql@postgresql.org Subject: Re: how to do this query? Date: Tue, 20 May 2003 17:36:47 +0100 User-Agent: KMail/1.4.3 References: <20030520160011.81254.qmail@web41803.mail.yahoo.com> In-Reply-To: <20030520160011.81254.qmail@web41803.mail.yahoo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200305201736.47227.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/390 X-Sequence-Number: 13555 On Tuesday 20 May 2003 5:00 pm, ww zz wrote: > New to sql and may be a simple question for you: > > I have four tables > > sample: sid, sname > make: sid, mdate > measure: sid, mdate, rid > result: rid, resultdata > > for a gaven sample it always has a sid and sname, but > it may or may not have any entries in the other > tables, the sample could be measured more than once > and each measure give a result row. You'll want to use a LEFT JOIN, something like: SELECT s.sid, s.sname, m.mdate, m.rid, r.resultdata FROM sample s LEFT JOIN measure m ON s.sid=3Dm.sid LEFT JOIN result ON=20 m.rid=3Dr.rid You'll get nulls where there are no matches. --=20 Richard Huxton