Re: left outer join without rows from "left" table

From: Scara Maccai <m_lists(at)yahoo(dot)it>
To: Sam Mason <sam(at)samason(dot)me(dot)uk>, pgsql-general(at)postgresql(dot)org
Subject: Re: left outer join without rows from "left" table
Date: 2009-02-16 16:08:42
Message-ID: 105049.7241.qm@web24611.mail.ird.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thank you: that's exactly what I needed.

> I think you want to use a full outer join with slightly unusual
> bracketing:
>
> SELECT t.id, COALESCE(a.t,b.t) AS t, a.a, b.b
> FROM tabid t LEFT JOIN (
> taba a FULL OUTER JOIN tabb b ON (a.id,a.t) = (b.id,b.t))
> ON t.id = COALESCE(a.id,b.id);
>
> This will start by doing the inner most thing first, join taba to tabb
> matching rows where the id and timestamp is the same, then go on to
> match these to tabid. The COALESCEs are needed because when either side
> is missing their values will be NULL and hence we need to look at both.

Passa a Yahoo! Mail.

La webmail che ti offre GRATIS spazio illimitato,
antispam e messenger integrato.
http://it.mail.yahoo.com/              

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Chris Mayfield 2009-02-16 16:09:59 Re: clearing the buffer cache
Previous Message Craig Ringer 2009-02-16 15:12:14 Re: idle DB and resources