From: Richard Huxton <dev@archonet.com>
To: ww zz <ts_999@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: Re: how to do this query?
Date: Tue, 20 May 2003 17:36:47 +0100
Message-ID: <200305201736.47227.dev@archonet.com> (raw)
In-Reply-To: <20030520160011.81254.qmail@web41803.mail.yahoo.com>
References: <20030520160011.81254.qmail@web41803.mail.yahoo.com>
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=m.sid LEFT JOIN result ON
m.rid=r.rid
You'll get nulls where there are no matches.
--
Richard Huxton
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: dev@archonet.com, ts_999@yahoo.com
Subject: Re: how to do this query?
In-Reply-To: <200305201736.47227.dev@archonet.com>
* 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