From: Stijn Vanroye <s.vanroye@farcourier.com>
To: pgsql-sql@postgresql.org
Cc: Edmund Bacon <ebacon@onesystem.com>
Subject: Re: a wierd query
Date: Mon, 17 May 2004 09:25:52 +0200
Message-ID: <71E201BE5E881C46811BA160694C5FCB046738@fs1000.farcourier.com> (raw)
Are you sure about that Edmund?
I have the following query:
select distinct on (task_id, date) task_id, workhour_id, date from
(
select task_id, workhour_id, begindate as date from workhour
UNION
select task_id, workhour_id, enddate as date from workhour
)as dist1
which returns me 2763 rows in my case
if I use the query without the top level select, like this:
select task_id, workhour_id, begindate as date from workhour
UNION
select task_id, workhour_id, enddate as date from workhour
I get 7146 rows.
If I understand correctly there would be no need for the top level select if UNION would be to only return unique values. But given my test results this doesn't seem to be the case. Am I missing something or am I misinterpreting something? I mean I'm sure you get this information out of the documentation, that's why this question has risen.
Kind regards,
Stijn Vanroye
> -----Original Message-----
> From: Edmund Bacon [mailto:ebacon@onesystem.com]
> Sent: donderdag 13 mei 2004 17:28
> To: sad
> Cc: pgsql-sql@postgresql.org
> Subject: Re: [SQL] a wierd query
>
>
> sad wrote:
> > select distinct a as F from table
> > union
> > select distinct b as F from table;
> >
>
> Note that UNION only returns the unique values of the union
> You can get repeated values by using UNION ALL.
>
>
> --
> Edmund Bacon <ebacon@onesystem.com>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: s.vanroye@farcourier.com, ebacon@onesystem.com
Subject: Re: a wierd query
In-Reply-To: <71E201BE5E881C46811BA160694C5FCB046738@fs1000.farcourier.com>
References: <71E201BE5E881C46811BA160694C5FCB046738@fs1000.farcourier.com>
* 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