Re: a wierd query - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: a wierd query
Date
Msg-id 20040517075834.H21709@megazone.bigpanda.com
Whole thread Raw
In response to Re: a wierd query  ("Stijn Vanroye" <s.vanroye@farcourier.com>)
List pgsql-sql
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.


pgsql-sql by date:

Previous
From: "Stijn Vanroye"
Date:
Subject: Re: a wierd query
Next
From: PS PS
Date:
Subject: Max Columns in a SQL Select