Antw: Problem with joins

Gerhard Dieringer <dieringg@eba-haus.de>

From: "Gerhard Dieringer" <DieringG@eba-haus.de>
To: <jean-marc.libs@obs.coe.int>
Cc: <pgsql-sql@postgresql.org>
Date: 2000-07-05T10:31:16Z
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