Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Selecting rows in ranges

0 views
Skip to first unread message

Jane

unread,
Sep 11, 2003, 12:00:56 PM9/11/03
to
What is the fastest way to select rows x to x in a table using db2?

Following is the query to do this in Oracle. What is the equivalent in db2?
==================================================================
SELECT *
FROM
(select inner.*, rownum rnum
from
(SELECT s.tableA_id xyz0, s.crtd_dtt xyz1,
s.tableA_id xyz2, s.tableA_id
xyz3, s.tableA_num xyz4, s.tableA_desc xyz5,
s.cur_optlstat_id xyz6, s.display_status xyz7 FROM tableA_t s
WHERE 1 = 1
AND s.tableA_id > '65185'
AND s.display_status = 5005
order by s.crtd_dtt desc, s.tableA_id) inner
where rownum < 100)
WHERE rnum >= 37
==================================================================
Thanks,
-Jane

Knut Stolze

unread,
Sep 11, 2003, 12:25:26 PM9/11/03
to
Jane <jane_e...@i2.com> wrote:

I would do it like this:

SELECT *
FROM ( SELECT ...,
row_number() over(order by s.crtd_dtt desc, s.tableA_id)
FROM tableA_t s
WHERE s.tableA_id > '65185' AND
s.display_status = 5005 ) AS inner(..., rnum)
WHERE rnum BETWEEN 37 AND 99

--
Knut Stolze
Information Integration
IBM Germany / University of Jena

Jane

unread,
Sep 11, 2003, 8:18:31 PM9/11/03
to
Knut,

Thanks for the response. Does this type of query perform well? We
have Web application and we are going to use this type of query to
allow users to jump pages. The tables will have over 5 million
records.

Thanks,
-Jane

Mark A

unread,
Sep 11, 2003, 8:21:47 PM9/11/03
to
"Jane" <jane_e...@i2.com> wrote in message
news:75f068bb.03091...@posting.google.com...

Just for starters, you need to explain what indexes you have on the table(s)
accessed before and estimate of query performance can be determined.


0 new messages