Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: SELECT DISTINCT ON and ORDER BY



On Fri, 28 Mar 2008, Sam Mason <sam(at)samason(dot)me(dot)uk> writes:
> On Fri, Mar 28, 2008 at 01:12:49PM +0100, Stanislav Raskin wrote:
>> The result in this case should be:
>> 
>> id value  order_field
>> 3   10      1
>> 5   12      2
>> 4    5      8

Yet another lame solution:

test=# SELECT max(id) AS id, min(value) AS value, min(weight) AS weight
         FROM tmp
        GROUP BY value
        ORDER BY min(weight);
 id | value | weight
----+-------+--------
  3 |    10 |      1
  5 |    12 |      2
  4 |     5 |      8
(3 rows)


Regards.



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group