Antw: Problem with joins

Поиск
Список
Период
Сортировка
От Gerhard Dieringer
Тема Antw: Problem with joins
Дата
Msg-id s9632aa2.096@kopo001
обсуждение исходный текст
Ответы Re: Antw: Problem with joins  ("Jean-Marc Libs" <jean-marc.libs@obs.coe.int>)
Список 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 по дате отправления:

Предыдущее
От: "Jean-Marc Libs"
Дата:
Сообщение: Problem with joins
Следующее
От: Antti Linno
Дата:
Сообщение: GROUP by