• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2665
  • Last Modified:

limit and offset clauses

Hi

I am migrating a mySQL application to Sybase. What is the equivalent SQL in Sybase for the LIMIT OFFSET clauses? ie to select 5 rows (limit) starting from the 10th row (offset).

Keith
0
keithcsl
Asked:
keithcsl
1 Solution
 
bretCommented:
There is no direct equivalent.

You can use "set rowcount <x>" to limit the results of a query to <x> rows, but there is no offset.

You can also select the result set (full or limited by SET ROWCOUNT) into a temptable, adding
an identity column, then use the values in the identity column to select subsets:

select a,b,c, rownum = identity(8) into #foo from mytable
select * from #foo where rownum between 10 and 15
drop table #foo
go
0
 
ChrisKingCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: bret

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

ChrisKing
EE Cleanup Volunteer
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now