Re: DISTINCT ON - Mailing list pgsql-sql

From Michael Glaesemann
Subject Re: DISTINCT ON
Date
Msg-id D8226C7A-638D-498A-81A5-AAEE5B5727E9@myrealbox.com
Whole thread Raw
In response to DISTINCT ON  ("Jeremy Palmer" <palmerj@xtra.co.nz>)
Responses Re: DISTINCT ON
List pgsql-sql
On Nov 19, 2005, at 7:49 , Jeremy Palmer wrote:

> SELECT DISTINCT ON (vector_id, obs_type)
>        id
> FROM   observation
> ORDER  BY vector_id,
>        obs_type,
>        date DESC;
>
> However the documentation also states that "DISTINCT ON" is not  
> part of the
> SQL standard and should be avoided when possible, stating that  
> aggregations
> and sub-queries should be used instead...
>
> How would this be done in this scenario?


Something like:

select max(date), id
from observation
group by vector_id, obs_type;

Do test to see which is better in your situation.

Michael Glaesemann
grzm myrealbox com





pgsql-sql by date:

Previous
From: "Jeremy Palmer"
Date:
Subject: DISTINCT ON
Next
From: "Jeremy Palmer"
Date:
Subject: Re: DISTINCT ON