Search Postgresql Archives

Re: Distinct on a non-sort column

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Cstdenis <lists@xxxxxxxxxxx> 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

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux