View Single Post
  #2  
Old 11-23-2007, 04:49 AM
priyan priyan is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 133
priyan is on a distinguished road
Default Re: Retrieve only the Nth row from a table?

MySQL

create table test_nthrow
( id integer
, name varchar(100)
);
insert into test_nthrow values (1,'row 1');
insert into test_nthrow values (2,'row 2');
insert into test_nthrow values (3,'row 3');
insert into test_nthrow values (4,'row 4');
insert into test_nthrow values (5,'row 5');

to get nth row use (n-1) in LIMIT condition since mysql rownumber starting from 0
to get 5th row
select * from test_nthrow limit 4,1
Quote:
Result
id name
5 row 5

Oracle
In oracle you may use this query to get 5th row
select * from (select ROWNUM rn,t.* FROM test_nthrow t) WHERE rn=5

This is just one way getting Nth row, you can use alternate method also in this case .
__________________
Keep smiling...
Reply With Quote