Re: ranked subqueries vs distinct question

From: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: ranked subqueries vs distinct question
Date: 2008-05-14 15:46:02
Message-ID: 20080514154602.GT4401@merkur.hilbert.loc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Justin 2008-05-14 15:47:52 Re: rounding problems
Previous Message Robert Treat 2008-05-14 15:39:16 Re: Alias in the HAVING clause