From: Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>
To: pgsql-sql@postgresql.org
Subject: Re: sub-limiting a query
Date: Sat, 17 Feb 2007 19:40:00 +0100
Message-ID: <20070217183959.GA29756@apartia.fr> (raw)
In-Reply-To: <45D747B4.5050900@gmail.com>
References: <20070217125634.GA20589@apartia.fr>
<45D747B4.5050900@gmail.com>
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!
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: vindex+lists-pgsql-sql@apartia.org
Subject: Re: sub-limiting a query
In-Reply-To: <20070217183959.GA29756@apartia.fr>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox