Re: sub-limiting a query - Mailing list pgsql-sql

From Louis-David Mitterrand
Subject Re: sub-limiting a query
Date
Msg-id 20070217183959.GA29756@apartia.fr
Whole thread Raw
In response to Re: sub-limiting a query  ("M.P.Dankoor" <m.p.dankoor@gmail.com>)
List pgsql-sql
On Sat, Feb 17, 2007 at 07:21:40PM +0100, M.P.Dankoor wrote:
> Louis-David Mitterrand wrote:
> >  
> I thought of another solution, actually it's of those top n query tricks 
> that I picked up somewhere, can't remember
> where.
> Assuming that your table is called shows, the following query should 
> give you the results you want (hope so)
> 
> SELECT *
> FROM shows a
> WHERE 3 > (SELECT COUNT(*)
>           FROM shows b
>           WHERE b.created_on >= a.created_on
>           and a.show_type = b.show_type)

This is stunning and it works!

I can barely understand the query: it's so terse it hurts :)

/me goes back studying it


Thanks a lot!


pgsql-sql by date:

Previous
From: "M.P.Dankoor"
Date:
Subject: Re: sub-limiting a query
Next
From: Bruce Momjian
Date:
Subject: Re: Odd PL/PgSQL Error -- relation "X" does not exist when using index expression