X-Original-To: pgsql-sql@postgresql.org Received: from localhost (unknown [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 3EC65924E3E for ; Tue, 20 May 2003 12:47:27 -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 19542-05 for ; Tue, 20 May 2003 12:47:22 -0400 (EDT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by developer.postgresql.org (Postfix) with ESMTP id 99304925044 for ; Tue, 20 May 2003 12:46:38 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 730A3D622; Tue, 20 May 2003 09:46:37 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 68C475C0C; Tue, 20 May 2003 09:46:37 -0700 (PDT) Date: Tue, 20 May 2003 09:46:37 -0700 (PDT) From: Stephan Szabo To: ww zz Cc: Subject: Re: how to do this query? In-Reply-To: <20030520160011.81254.qmail@web41803.mail.yahoo.com> Message-ID: <20030520094321.T68048-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/391 X-Sequence-Number: 13556 On Tue, 20 May 2003, 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. > question: > how do I do a query that given a sid, it will retrieve > all the information available in the four tables, if > there are available. If, for example, all tables have > some entry for a gave sample it will retreve all the > information, if the "measure" and "result" are empty > for that sample it will give only the 'sample' and > 'make' information.... Well, you're not going to get a limited column set, but you can get NULLs in the non-applicable table columns by using outer joins. Maybe something like something like select * from sample left outer join make using (sid) left outer join measure using (sid) left outer join result using (rid) where sid=;