Antw: Problem with joins - Mailing list pgsql-sql

From Gerhard Dieringer
Subject Antw: Problem with joins
Date
Msg-id s9632aa2.096@kopo001
Whole thread Raw
Responses Re: Antw: Problem with joins
List 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
fromsource,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





pgsql-sql by date:

Previous
From: "Jean-Marc Libs"
Date:
Subject: Problem with joins
Next
From: Antti Linno
Date:
Subject: GROUP by