How to get first 5 Records then next 5 records till end of row count in SQL -Oracle

Showing Answers 1 - 29 of 29 Answers

Mainak Aich

  • Feb 28th, 2006
 

We can get the first 5 records by the following sql:(Let the table is emp)

select * from emp where rownum<6

Then we can get the next 5 records by the following sql:

select * from emp where rownum<6 MINUS select * from emp where rownum<11

and so on...

  Was this answer useful?  Yes

KS

  • Mar 4th, 2006
 

It should be:Select * from emp where rownum<6;thenSelect * from emp where rownum<11 MINUS select * from emp where rownum <6;and so on

  Was this answer useful?  Yes

reddeppa

  • Apr 4th, 2006
 

select * from emp where not in (select rownum betwen 5 and count(rownum)-5 from emp)

  Was this answer useful?  Yes

amrita

  • May 5th, 2006
 

hello your answer is correct but the sequence is wrong

To get first five records

select aud_trn_issue_header.*,rownum from aud_trn_issue_header where rownum < 6

To get the next five records

select aud_trn_issue_header.*,rownum from aud_trn_issue_header where rownum < 11 minus
select aud_trn_issue_header.*,rownum from aud_trn_issue_header where rownum<6

and so on..............

bye

  Was this answer useful?  Yes

Santhosh

  • May 6th, 2006
 

Hello,

Please post correct queries after checking.

  Was this answer useful?  Yes

Al Di Meola

  • Jun 7th, 2006
 

select * from

(select rownum rowpos, emp.* from emp) inline_emp

where inline_emp.rowpos between 5 and 10

 

This should work for any rownum range......

 

~Al Di Meola

  Was this answer useful?  Yes

cgk1983

  • Oct 27th, 2006
 

select A.R,A.ename from (select rownum R,ename from emp)A where A.r between &start and &end
/

  Was this answer useful?  Yes

Sandeep Bawalia

  • May 22nd, 2007
 

select d.amount from (select t.tadichallan_amt amount,rank() over (order by t.tadichallan_amt desc) as Rank1
from tae_challan_det t where t.tadichallan_amt is not null )d
where Rank1 between '&n' and '&d'

  Was this answer useful?  Yes

sharmasl

  • Mar 6th, 2009
 

Please Try This Query on SQL Prompt And see the best result as per Requirement.

select * from
(select rownum rowno, emp.* from emp) line_emp where line_emp.rowno between &a and &b;

Thanks,
Salil Sharma

  Was this answer useful?  Yes

pramod kumar behera

  • Aug 21st, 2011
 

create sequence seq_test
start with 1
increment by 1
maxvalue 5
minvalue 1
cycle
cache 2;

  Was this answer useful?  Yes

Ramesh

  • Oct 31st, 2011
 

Select * from emp where rownum<=5
union
Select * from emp where rownum<=10
.
.
.
Select * from emp where rownum<=(select max(rownum) from emp)-5
union
Select * from emp where rownum<=(select max(rownum) from emp)

  Was this answer useful?  Yes

SIVA KARTHIK

  • Dec 13th, 2011
 

SELECT * FROM (SELECT ROWNUM R ,ENO FROM EMP) WHERE R BETWEEN &F AND &L
/

  Was this answer useful?  Yes

ananymous

  • Jan 6th, 2012
 

The best ans given above is

Code
  1.  

  2. SELECT * FROM (SELECT ROWNUM R ,CUST_NO FROM S1_ETL.CA_STTC_DETS_1) WHERE R BETWEEN &F AND &L

  Was this answer useful?  Yes

Naazneen

  • Sep 6th, 2012
 

Using pagination

Code
  1. SELECT *

  2.     FROM (

  3.     SELECT empno, sal,

  4.   row_number()

  5.          over (ORDER BY empno ASC) rn

  6.     FROM emp

  7.     )

  8.     WHERE rn BETWEEN 1 AND 5

  9.     ORDER BY sno ASC;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions