Re: how to do this query? - Mailing list pgsql-sql

From Richard Huxton
Subject Re: how to do this query?
Date
Msg-id 200305201736.47227.dev@archonet.com
Whole thread Raw
In response to how to do this query?  (ww zz <ts_999@yahoo.com>)
List pgsql-sql
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


pgsql-sql by date:

Previous
From: "Jan Bodey"
Date:
Subject: Date comparison question
Next
From: Stephan Szabo
Date:
Subject: Re: how to do this query?