Re: Distinct on a non-sort column - Mailing list pgsql-general

From Tom Lane
Subject Re: Distinct on a non-sort column
Date
Msg-id 17666.1320534691@sss.pgh.pa.us
Whole thread Raw
In response to Re: Distinct on a non-sort column  (Cstdenis <lists@on-track.ca>)
Responses Re: Distinct on a non-sort column
List pgsql-general
Cstdenis <lists@on-track.ca> writes:
> If I understand that you are proposing as

>     select * from
>                  (select distinct on (user_id) * from stories as s order
>     by user_id) as foo
>     order by date_submitted desc limit 10;

No, you always need to sort by *more* columns than are listed in
DISTINCT ON.  That's what determines which row is picked in each
DISTINCT group.  Read the SELECT reference page's example of how
to use DISTINCT ON.

            regards, tom lane

pgsql-general by date:

Previous
From: Cstdenis
Date:
Subject: Re: Distinct on a non-sort column
Next
From: Tatsuo Ishii
Date:
Subject: Some services of pgfoundry down?