pagination (rownum) with the twist of reporting total count [message #220362] |
Tue, 20 February 2007 07:00 |
solmyr72
Messages: 3 Registered: January 2007
|
Junior Member |
|
|
Hi,
Could anyone please advise on the most efficient way to combine pagination (rownum) *but* also report the total count of results?
Kind of like Google tells you: "showing results 21-30 out of 10000" ?
Or do you have to run 2 separate queries, one to extract the required page, and another to extract 'count(*)' ?
My 'select' is quite expensive, so I was hoping to avoid it.
Example:
Suppose you select all 'employees' who belong to 'HR', and show them in a web page, 10 employees per page, while also adding a message on the total results ( so in page 3 the message could be "showing results 21-30 out of total 1000 results" ).
In 2 queries it would be:
1. Select page 3:
select * from (
select e.*, rownum rw
from employees e
where e.dept_name='HR'
)
where rw between 21 and 30;
2. Count total results:
select count(*) from employees e
where where e.dept_name='HR';
Is there a better way ?
Thanks very much.
|
|
|
|