Home » RDBMS Server » Server Administration » returning only certain rows from a query
returning only certain rows from a query [message #371700] Mon, 27 November 2000 14:49 Go to next message
Paul
Messages: 164
Registered: April 1999
Senior Member
I would like to select say rows 5-20 from the results of a query. I know how to get the first n rows, but I would like to get the nth through the n+nth rows. Is that possible?
Re: returning only certain rows from a query [message #371701 is a reply to message #371700] Mon, 27 November 2000 15:11 Go to previous messageGo to next message
Bala
Messages: 205
Registered: November 1999
Senior Member
Hi Paul,

Use this example

select * from
(
select rownum rnum, a.*
from (select *
from t1) a
where rownum <= 20
)
where rownum >= 5;

Bala.
Re: returning only certain rows from a query [message #371702 is a reply to message #371701] Mon, 27 November 2000 15:29 Go to previous messageGo to next message
Paul
Messages: 164
Registered: April 1999
Senior Member
I tried this with my Oracle SQL client and it would not work. Taking out the >=5 it does work. I think the rownum checking only works when doing <=. Am I wrong?
Sorry i over looked....... [message #371704 is a reply to message #371701] Mon, 27 November 2000 15:45 Go to previous messageGo to next message
Bala
Messages: 205
Registered: November 1999
Senior Member
Hi,

It should be where rnum >= 5

select * from
(
select rownum rnum, a.*
from (select *
from client_names) a
where rownum <= 20
)
where rnum > 5
/

Bala
sorry i have over looked [message #371705 is a reply to message #371700] Mon, 27 November 2000 15:47 Go to previous messageGo to next message
Bala
Messages: 205
Registered: November 1999
Senior Member
Hi
It should be rnum >= 5

select * from
(
select rownum rnum, a.*
from (select *
from client_names) a
where rownum <= 20
)
where rownum >= 5
/
Re: Sorry i over looked....... [message #371706 is a reply to message #371701] Mon, 27 November 2000 15:48 Go to previous messageGo to next message
Paul
Messages: 164
Registered: April 1999
Senior Member
Thanks that worked.
Re: Sorry i over looked....... [message #371709 is a reply to message #371701] Tue, 28 November 2000 01:13 Go to previous message
J.S HAN
Messages: 12
Registered: November 2000
Junior Member
Hi,
How about this SQL

select x.*
from (select rownum rnum , a.* from tab1 a) x
where no between 5 and 10
/
Previous Topic: reading text file(csv) into a database table
Next Topic: SQL- Help
Goto Forum:
  


Current Time: Tue May 07 03:47:52 CDT 2024