Re: Select Rows With Only One of Two Values

From: Chris Angelico <rosuav(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Select Rows With Only One of Two Values
Date: 2012-07-21 01:55:04
Message-ID: CAPTjJmrb=KZmy-CWi8QzQgakD54RWa2+ZWcNbcw_KHJbmSFrXQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Jul 21, 2012 at 6:52 AM, Alban Hertroys <haramrae(at)gmail(dot)com> wrote:
> I don't think the DISTINCT is necessary there, doesn't EXCEPT already return a distinct set, just like UNION (hence the existence of UNION ALL)?
>
> It can also be written as a correlated subquery:

Oops, yes. I usually use UNION ALL and friends, and IMHO that "ALL"
keyword is one of SQL's weirder warts. Most of the time, a wordier
query involves more work (SELECT DISTINCT vs SELECT), but in this odd
instance, it's the other way around.

And yes, it can. Not sure whether the subquery or EXCEPT notation is
more readable. Much of a muchness, really.

ChrisA

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Chris Angelico 2012-07-21 01:57:43 Re: Pg_ctl promote -- wait for slave to be promoted fully ?
Previous Message Craig Ringer 2012-07-21 01:41:09 Re: big database resulting in small dump