Re: how to do this query?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: ww zz <ts_999(at)yahoo(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: how to do this query?
Date: 2003-05-20 16:46:37
Message-ID: 20030520094321.T68048-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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=<value>;

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Stefano Vita Finzi 2003-05-20 16:53:08 plpgsql recursion
Previous Message Richard Huxton 2003-05-20 16:36:47 Re: how to do this query?