> I want to get a list of data sources with the corresponding data,
> if the data exists, or with null, if the data doesn't. But anyway
> I need the data sources (all of them).
You want an outer join. Postgres doesn't have that yet, but you can
mimic it.
> 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.
Close. Try
select source_name,data_value
from source,data where data_source_id=source_id
union
select source_name,source_id,NULL from source
where source_id not in (select data_source_id from data);
- Thomas