Re: Problem with joins - Mailing list pgsql-sql

From Thomas Lockhart
Subject Re: Problem with joins
Date
Msg-id 39634780.17592BFF@alumni.caltech.edu
Whole thread Raw
In response to Problem with joins  ("Jean-Marc Libs" <jean-marc.libs@obs.coe.int>)
List pgsql-sql
> 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
fromsource  where source_id not in (select data_source_id from data);
 
                        - Thomas


pgsql-sql by date:

Previous
From: Paul McGarry
Date:
Subject: ERROR: ExecEvalAggref: no aggregates in this expression context
Next
From: Thomas Lockhart
Date:
Subject: Re: Aww, sorry (last day of month)