• Post Reply Bookmark Topic Watch Topic
  • New Topic

SQL Server limiting result set

 
Ali Ekber
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to limit the result set coming from a SQL Server query. I can get the top 10 by SELECT TOP 10. But how do I get the rows from 11 to 20, for example? This is very easy in MySQL, but don't know the syntax for SQL server. Is this possible without stored procedures? Thanks.
 
Amy Medrat
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Ali, I hope this would help

select * from tableName
where rowid in (select rowid from tableName where rownum < 21
minus
select rowid from tableName where rownum< 11)
 
Ali Ekber
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amy, what are rowid and rownum? Are they keywords in SQL server? I am getting syntax error for them.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, but they are in Oracle. That query won't run in SQL Server.
 
chien ajax
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Get the rows from 21 to 30 in MSSQL

Perfect Version


[ March 10, 2006: Message edited by: chien ajax ]
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!