Received: from merganser.its.uu.se (merganser.its.uu.se [130.238.6.236]) by hub.org (8.9.3/8.9.3) with ESMTP id OAA14563 for ; Sat, 18 Dec 1999 14:01:34 -0500 (EST) (envelope-from peter@localhost.its.uu.se) Received: from regulus.its.uu.se ([130.238.7.19]:62953 "EHLO regulus.its.uu.se") by merganser.its.uu.se with ESMTP id ; Sat, 18 Dec 1999 17:12:03 +0100 Received: from peter (helo=localhost) by regulus.its.uu.se with local-esmtp (Exim 3.02 #2) id 11zMUH-0000EZ-00; Sat, 18 Dec 1999 17:13:41 +0100 Date: Sat, 18 Dec 1999 17:13:41 +0100 (CET) From: Peter Eisentraut To: Mitch Vincent cc: pgsql-sql@postgresql.org Subject: Re: [SQL] count() question In-Reply-To: <021101bf490b$d43b7ec0$0300000a@doot.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT Sender: Peter Eisentraut On 1999-12-17, Mitch Vincent mentioned: > So my question is, is there anyway you can get the total number of results > (using count() or something) and still use the limit directive in the same > query? I tried looking at the number of result rows too but 10 (the limit) > is all I come up with. > > I would really like to avoid doing 2 full queries here, if anyone has any > suggestions please let me know. Why do you want to avoid that? If you need two different results then you probably have to use two different queries. I assume you need the count to display something like "x matches found" and use LIMIT/OFFSET to step through them page by page. In that case there is really no way but to query twice. If your query is really complicated and slow you might want to put the complete query results in a temporary table, and select the count and the to-be-displayed data from there. -- Peter Eisentraut Sernanders väg 10:115 peter_e@gmx.net 75262 Uppsala http://yi.org/peter-e/ Sweden