IT Community - Software Programming, Web Development and Technical Support

Retrieve only the Nth row from a table?

This is a discussion on Retrieve only the Nth row from a table? within the Database Support forums, part of the Web Development category; can one Retrieve only the Nth row from a table? Thanks in advance...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Database Support

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 11-22-2007, 05:37 AM
santhakumar santhakumar is offline
D-Web Genius
 
Join Date: Mar 2007
Posts: 928
santhakumar is on a distinguished road
Default Retrieve only the Nth row from a table?

can one Retrieve only the Nth row from a table?

Thanks in advance
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #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...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 12-19-2007, 04:11 AM
santhakumar santhakumar is offline
D-Web Genius
 
Join Date: Mar 2007
Posts: 928
santhakumar is on a distinguished road
Default Re: Retrieve only the Nth row from a table?

Hi Priyan

it is very useful for me. but i need query for sql server 2005
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 12-19-2007, 04:43 AM
srikumar_l srikumar_l is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 196
srikumar_l is on a distinguished road
Default Re: Retrieve only the Nth row from a table?

Hi Santha,

I think this will help you ,

Begin
With ProjectTable As
(Select *, Row_Number()Over(Order By ProjectID) as RowNum from Project)
Select * from ProjectTable Where RowNum = 9
End

Here the 'ProjectTable' is the Common Table Expression used to hold the result set of the project table temporarily.
You can use any table instead of project table.

Tell me How usefull was it

Thanks,
L.Srikumar
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 12-19-2007, 05:08 AM
theone theone is offline
D-Web Sr.Programmer
 
Join Date: Jun 2007
Posts: 129
theone is on a distinguished road
Default Re: Retrieve only the Nth row from a table?

Hi Santha,

You can try this also,

Select *
From (Select *,(Row_Number() Over (Order By ProjectID)) As Rownum
From Project) P
Where P.Rownum = 10
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6  
Old 01-21-2008, 12:07 AM
santhakumar santhakumar is offline
D-Web Genius
 
Join Date: Mar 2007
Posts: 928
santhakumar is on a distinguished road
Default Re: Retrieve only the Nth row from a table?

Hi

This query is very useful for me . its working fine in sql server . can u please explain this query.?

Thank u
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7  
Old 11-14-2008, 04:12 AM
levelup2 levelup2 is offline
D-Web Trainee
 
Join Date: Nov 2008
Posts: 6
levelup2 is on a distinguished road
Default Re: Retrieve only the Nth row from a table?

is really useful for me, I am glad to read it here.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Retrieve a Cookie Value? sundarraja PHP Programming 4 04-02-2008 06:00 AM
Retrieve mails from server kingmaker C# Programming 6 12-14-2007 10:42 PM
What is the difference between DELETE TABLE and TRUNCATE TABLE commands in SQL Server oxygen Database Support 6 11-23-2007 05:17 AM
How do I retrieve the values from the URL? Pvinothkumar HTML, CSS and Javascript Coding Techniques 1 09-13-2007 05:30 AM
which method to use so that last inserted value can be retrieve. KiruthikaSambandam Database Support 1 08-06-2007 11:13 PM


All times are GMT -7. The time now is 02:17 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0