Re: sub-limiting a query

From: Louis-David Mitterrand <vindex+lists-pgsql-sql(at)apartia(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: sub-limiting a query
Date: 2007-02-17 18:40:00
Message-ID: 20070217183959.GA29756@apartia.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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!

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Momjian 2007-02-18 01:47:57 Re: Odd PL/PgSQL Error -- relation "X" does not exist when using index expression
Previous Message M.P.Dankoor 2007-02-17 18:21:40 Re: sub-limiting a query