Re: ranked subqueries vs distinct question - Mailing list pgsql-general

From Karsten Hilbert
Subject Re: ranked subqueries vs distinct question
Date
Msg-id 20080514154602.GT4401@merkur.hilbert.loc
Whole thread Raw
In response to Re: ranked subqueries vs distinct question  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
List pgsql-general
On Wed, May 14, 2008 at 08:21:00AM -0700, Stephan Szabo wrote:

> Can't you just do something like order by name, rank as part of the
> distinct on subselect to force it to pick the rank 1 row for a given name?
>
> So, basically
> select * from
>  ( select distinct on ... order by name, rank )
> order by rank, name;

OK, ordering twice, ..., once to bubble up by rank so the
distinct on picks the rank 1 sub-results ..., second to time
get the final order by name within the ranks. Sounds like an
idea I didn't think of. Will try that. Thanks for the
suggestion !

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346

pgsql-general by date:

Previous
From: Robert Treat
Date:
Subject: Re: Alias in the HAVING clause
Next
From: Justin
Date:
Subject: Re: rounding problems