Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Query for selecting records in a range

Author  Topic 

rajvijaymohan
Starting Member

2 Posts

Posted - 2006-10-25 : 08:30:35

Is there any sql statement available to select 5th record to 16th record from a table ? (no field name can be given as a search criteria)

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-25 : 08:36:36
select top 5 * from (select top 16 * from mytable order by mycolumn) order by mycolumn desc.

There are lot of answers given here for pagination.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2006-10-25 : 09:09:34
It should be pointed out explicitly that in the absence of an ordering scheme, there is no concept of first, last, 5th, 16th or otherwise in set theory. A set is naturally unordered. This is why Peso has ordered both his derived table and outer select statement. If you exclude the order by clause on either, you may not get expected or consistant results.

Jay White
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-10-25 : 09:12:59
Job interview question.




CODO ERGO SUM
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-25 : 11:10:14
quote:
Originally posted by Michael Valentine Jones

Job interview question.




CODO ERGO SUM


No doubt

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -