?
Solved

Select records where rownum between some values

Posted on 2005-03-21
1
Medium Priority
?
7,958 Views
Last Modified: 2012-08-13
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
Comment
Question by:shyma_nk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
Jan Franek earned 90 total points
ID: 13598830
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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
The top devops trends for 2017 are focused on improved deployment frequency, decreased lead time for change and decreased MTTR.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question