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
 General SQL Server Forums
 New to SQL Server Programming
 limiting rows

Author  Topic 

Ed_LTS
Starting Member

5 Posts

Posted - 2005-09-22 : 18:33:51
I am trying to convert some mySql code to sqlserver and was amazed to see that sqlserver has no functionality to specify the rows of a select statement. In mySql its e.g. "SELECT * FROM table LIMIT 20, 10" this returns ten rows starting from row 21. Using TOP in sqlserver only returns the top n rows but what if I want row 20 to 30? Is there an easy way that I have just missed or does one realy have to do something like "SELECT TOP 60 * FROM myTable WHERE id NOT IN (SELECT TOP 40 id FROM myTable);"?

Hope you can reply with good news...

Ed

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-09-22 : 18:58:47
Here's the article discussing this:
http://www.sqlteam.com/item.asp?ItemID=566

Tara
Go to Top of Page

Ed_LTS
Starting Member

5 Posts

Posted - 2005-09-22 : 19:32:47
The article also suggests a similar subquery to my example. Is this really the only way? I find it rather messy.
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-09-22 : 22:51:32
It's probably the best way in SQL Server.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -