Re: how to do this query?

From: Richard Huxton <dev(at)archonet(dot)com>
To: ww zz <ts_999(at)yahoo(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: how to do this query?
Date: 2003-05-20 16:36:47
Message-ID: 200305201736.47227.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2003-05-20 16:46:37 Re: how to do this query?
Previous Message Jan Bodey 2003-05-20 16:22:38 Date comparison question