Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id C62729FB3FD for ; Sat, 17 Feb 2007 11:00:40 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 94635-09 for ; Sat, 17 Feb 2007 11:00:31 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.188]) by postgresql.org (Postfix) with ESMTP id 993F59FB3A0 for ; Sat, 17 Feb 2007 11:00:36 -0400 (AST) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de (node=mrelayeu5) with ESMTP (Nemesis), id 0ML25U-1HIR3C12KC-0006KT; Sat, 17 Feb 2007 16:00:34 +0100 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1HIR3B-0007yl-00 for pgsql-sql@postgresql.org; Sat, 17 Feb 2007 16:00:33 +0100 Date: Sat, 17 Feb 2007 16:00:33 +0100 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: sub-limiting a query Message-ID: <20070217150033.GA30177@a-kretschmer.de> References: <20070217125634.GA20589@apartia.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070217125634.GA20589@apartia.fr> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! User-Agent: Mutt/1.5.9i X-Provags-ID: kundenserver.de abuse@kundenserver.de login:51ea9561fc3f6d9539a2acd743e4748c X-Provags-ID2: V01U2FsdGVkX198k+JDzPiSs593ubZlp/NKQuOxkcrNWklF1Tc1i9vxlphDYKRCuuM3Q7KADZYL0bYdd1+7aJJ34nsViuGENOvmtcKAWcVftwV/bo9UPmfXOmEGkqiNWbnt X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.428 tagged_above=0 required=5 tests=AWL, BAYES_50, SPF_HELO_PASS X-Spam-Level: X-Archive-Number: 200702/182 X-Sequence-Number: 27516 am Sat, dem 17.02.2007, um 13:56:35 +0100 mailte Louis-David Mitterrand folgendes: > 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 > You can try to divide this into 2 selects: First, select the last 10 entered show, this is simple. Then, write a stored proc. Within, select for every show_type the 2 last events. Both results combine with UNION ALL. I know, the hard part is the function. I havn't time at the moment to write an example, we have guests... Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net