Antw: Problem with joins

From: "Gerhard Dieringer" <DieringG(at)eba-haus(dot)de>
To: <jean-marc(dot)libs(at)obs(dot)coe(dot)int>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Antw: Problem with joins
Date: 2000-07-05 10:31:16
Message-ID: s9632aa2.096@kopo001
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


Jean-Marc Libs wrote:
>...
>I have also tried:
>select source_name,data_value from source,data where data_source_id=source_id union select source_name,source_id,NULL from source,data

>This is a bit better, in the sense that I get back all I need, but there
>are too many lines: when there is data, I get the line with the data value
>and also with NULL.
>...

You are on the right way. Change your querry to

select source_name,data_value
from source,data
where data_source_id=source_id
union
select source_name,source_id
from source
WHERE source_id NOT IN (SELECT source_id FROM data);

and you will get your expected result.

BTW this simulates an outer join.

Gerhard

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Antti Linno 2000-07-05 11:14:55 GROUP by
Previous Message omid omoomi 2000-07-05 08:38:40 Re: Median