Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 7CFDC9FB537 for ; Sat, 17 Feb 2007 13:42:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 67076-09 for ; Sat, 17 Feb 2007 13:42:12 -0400 (AST) X-Greylist: delayed 00:05:50.773986 by SQLgrey-1.7.4 Received: from smtp-vbr12.xs4all.nl (smtp-vbr12.xs4all.nl [194.109.24.32]) by postgresql.org (Postfix) with ESMTP id 5B7D09FB3D2 for ; Sat, 17 Feb 2007 13:42:11 -0400 (AST) Received: from [192.168.1.3] (213-84-236-203.adsl.xs4all.nl [213.84.236.203]) (authenticated bits=0) by smtp-vbr12.xs4all.nl (8.13.8/8.13.8) with ESMTP id l1HHaIlD007426 for ; Sat, 17 Feb 2007 18:36:19 +0100 (CET) (envelope-from m.p.dankoor@gmail.com) Message-ID: <45D73CCD.6080203@gmail.com> Date: Sat, 17 Feb 2007 18:35:09 +0100 From: "M.P.Dankoor" User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: sub-limiting a query References: <20070217125634.GA20589@apartia.fr> In-Reply-To: <20070217125634.GA20589@apartia.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by XS4ALL Virus Scanner X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.07 tagged_above=0 required=5 tests=BAYES_50, SPF_NEUTRAL X-Spam-Level: * X-Archive-Number: 200702/185 X-Sequence-Number: 27519 Louis-David Mitterrand wrote: > Hello, > > I've got a table of shows with different types (movie, theater, > ballet,etc.) and I am looking for a select that can return the 10 last > entered shows AND at most 2 of each type. Is that possible in one query? > > The table looks basically like: > > created_on | timestamp without time zone > show_name | text > id_show | integer > show_type | text > id_show_subtype | integer > > ---------------------------(end of broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster > > Looks like a top n query and whilst there are many top-n query solution I'd refer you to a Joe Celko solution. Check the "top salesperson contest" and I think you should be able to work your problem (http://www.dbmsmag.com/9610d06.html) Mario