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

Select records where rownum between some values

Hi all,

I am new to Sybase. Can someone tell me how to retrieve a set of records from a select query result based on the rownum.
In Oracle I will do the same as follows to get the 5 employee ids whose salary position is between 5 and 10.
select * from (select empid, rownum num, from employee order by salary) temp
where temp.num between 5 and 10

Thanks in advance
0
shyma_nk
Asked:
shyma_nk
1 Solution
 
Jan FranekCommented:
There's nothing like row number in Sybase, so AFAIK it can't be done easily. But if you are on current version of ASE (with top functionality and derived tables), you can do it this way:

select top 5 * from ( select top 10 * from employee order by salary ) temp order by salary desc

If you are on older version of ASE, it can be done using set rowcount and temporary tables:

set rowcount 10
select * into #temp from employee order by salary
set rowcount 5
select * from #temp order by salary desc
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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