Re: [SQL] count() question

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Mitch Vincent <mitch(at)venux(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] count() question
Date: 1999-12-18 16:13:41
Message-ID: Pine.LNX.4.21.9912181655230.356-100000@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)gmx(dot)net 75262 Uppsala
http://yi.org/peter-e/ Sweden

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Eisentraut 1999-12-18 16:13:53 Re: [SQL] making 'like' queries quicker
Previous Message admin 1999-12-18 14:52:21 Re: [SQL] making 'like' queries quicker