X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 0BDB1D1C4E2 for ; Mon, 17 May 2004 12:01:31 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 08409-07 for ; Mon, 17 May 2004 12:01:09 -0300 (ADT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id 47DCFD1C952 for ; Mon, 17 May 2004 12:01:09 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id E24A1359DF; Mon, 17 May 2004 08:01:07 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id E0C3D3596B; Mon, 17 May 2004 08:01:07 -0700 (PDT) Date: Mon, 17 May 2004 08:01:07 -0700 (PDT) From: Stephan Szabo To: Stijn Vanroye Cc: pgsql-sql@postgresql.org, Edmund Bacon Subject: Re: a wierd query In-Reply-To: <71E201BE5E881C46811BA160694C5FCB046738@fs1000.farcourier.com> Message-ID: <20040517075834.H21709@megazone.bigpanda.com> References: <71E201BE5E881C46811BA160694C5FCB046738@fs1000.farcourier.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200405/145 X-Sequence-Number: 17859 On Mon, 17 May 2004, Stijn Vanroye wrote: > 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 This gets you first rows distincted by task_id, workhour_id and date and then only rows distincted by task_id and date (and an unpredictable workhour_id). > 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 This gets rows distincted by task_id, workhour_id and date.