This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes SQL Server limiting result set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL Server limiting result set" Watch "SQL Server limiting result set" New topic

SQL Server limiting result set

Ali Ekber
Ranch Hand

Joined: Jun 12, 2005
Posts: 41
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

Joined: Mar 05, 2006
Posts: 15
Hey Ali, I hope this would help

select * from tableName
where rowid in (select rowid from tableName where rownum < 21
select rowid from tableName where rownum< 11)

Ali Ekber
Ranch Hand

Joined: Jun 12, 2005
Posts: 41
Amy, what are rowid and rownum? Are they keywords in SQL server? I am getting syntax error for them.
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

No, but they are in Oracle. That query won't run in SQL Server.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
chien ajax

Joined: Aug 22, 2005
Posts: 1

Get the rows from 21 to 30 in MSSQL

Perfect Version

[ March 10, 2006: Message edited by: chien ajax ]
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: SQL Server limiting result set
It's not a secret anymore!