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 1AF2BD1B1AA for ; Tue, 18 May 2004 04:57:26 -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 85694-01 for ; Tue, 18 May 2004 04:57:07 -0300 (ADT) Received: from mail.cobweb.nl (mx1.cobweb.nl [80.242.96.4]) by svr1.postgresql.org (Postfix) with ESMTP id 66ECBD1B16E for ; Tue, 18 May 2004 04:57:04 -0300 (ADT) Received: from farcourier.com (dp3-26.dsl.cobweb.nl [193.67.120.154] (may be forged)) by mail.cobweb.nl (8.12.8/8.12.7) with ESMTP id i4I7v4u1017825 for ; Tue, 18 May 2004 09:57:10 +0200 (CEST) (envelope-from s.vanroye@farcourier.com) Content-Class: urn:content-classes:message Subject: Re: a wierd query MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Tue, 18 May 2004 09:56:29 +0200 Message-ID: <71E201BE5E881C46811BA160694C5FCB04673A@fs1000.farcourier.com> X-MIMEOLE: Produced By Microsoft Exchange V6.0.6249.0 X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [SQL] a wierd query Thread-Index: AcQ8H8z2PJuxPXA6R9uYryOZy8qTiwAiz4pA From: "Stijn Vanroye" To: Cc: "Stephan Szabo" 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/153 X-Sequence-Number: 17867 I understand, thanks. First: as I said in my previous post, the workhour_id was left behind by mi= stake and has since been removed. So it seems that I can ommit the distinct completely and just use the query= in it's simpelest form, like this: select employee_id, begindate as date from workhour UNION select employee_id, enddate as date from workhour And I would get a list of all dates (as well begin- as enddates) where a da= te can occure only once with each employee? Altough I didn't start this thread I'm learing some usefull things here, so= some thanks to the people who replied (and started the thread) are in plac= e here. Kind regards, Stijn Vanroye > -----Original Message----- > From: Stephan Szabo [mailto:sszabo@megazone.bigpanda.com] > Sent: maandag 17 mei 2004 17:01 > To: Stijn Vanroye > Cc: pgsql-sql@postgresql.org; Edmund Bacon > Subject: Re: [SQL] a wierd query >=20 > On Mon, 17 May 2004, Stijn Vanroye wrote: >=20 > > Are you sure about that Edmund? > > > > I have the following query: > > select distinct on (task_id, date) task_id,=20 > 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 >=20 > 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=20 > unpredictable > workhour_id). >=20 > > 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 >=20 > This gets rows distincted by task_id, workhour_id and date. >=20