pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Lockhart <lockhart@alumni.caltech.edu>
To: jml@obs.coe.int
Cc: pgsql-sql@postgresql.org
Subject: Re: Problem with joins
Date: Wed, 05 Jul 2000 14:34:40 +0000
Message-ID: <39634780.17592BFF@alumni.caltech.edu> (raw)
References: <Pine.LNX.4.21.0006051235590.29612-100000@centaure.obs.coe.int>

> 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



view thread (5+ messages)  latest in thread

Message-ID: <39634780.17592BFF@alumni.caltech.edu>
Permalink:  ../39634780.17592BFF@alumni.caltech.edu/
Also on:    postgresql.org/message-id/39634780.17592BFF@alumni.caltech.edu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: lockhart@alumni.caltech.edu, jml@obs.coe.int
  Subject: Re: Problem with joins
  In-Reply-To: <39634780.17592BFF@alumni.caltech.edu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox