This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JDBC 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


JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL Server limiting result set" Watch "SQL Server limiting result set" New topic
Author

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
Greenhorn

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
minus
select rowid from tableName where rownum< 11)


medRat
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
Bartender

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
Greenhorn

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 ]
 
GeeCON Prague 2014
 
subject: SQL Server limiting result set