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 2005 Forums
 Transact-SQL (2005)
 How to select records 11 to 20 in SQL SERVER?

Author  Topic 

mittalpa
Starting Member

2 Posts

Posted - 2009-06-23 : 11:32:15
Hi

I want to select records 11 to 20 in sql server. In MySQL this is how it is done. How can we do it in SQL SERVER 2005 and above?

SELECT * FROM employees LIMIT 10,10;

In MySQL, LIMIT x,y means skip the first x records, and then return the next y records.



Thanks
Pankaj

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-06-23 : 11:34:55
Use ROW_NUMBER() and choose rows >10 and < 21

as in

SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY empid) as row FROM Employees) a WHERE row > 10 and row <= 20

quote:
Originally posted by mittalpa

Hi

I want to select records 11 to 20 in sql server. In MySQL this is how it is done. How can we do it in SQL SERVER 2005 and above?

SELECT * FROM employees LIMIT 10,10;

In MySQL, LIMIT x,y means skip the first x records, and then return the next y records.



Thanks
Pankaj



Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-23 : 11:36:11
See here:
http://www.sqlteam.com/search.aspx?cx=011171816663894899992%3Aaow51lf_dim&cof=FORID%3A9&q=mysql+limit#1195


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-06-24 : 00:03:46
see this link it may help
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/09/12/return-top-n-rows.aspx
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-06-24 : 02:14:14
Refer point 4
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx

Madhivanan

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

- Advertisement -