Skip to content

Lawtec

Sections
Personal tools
You are here: Home Members admin's Home Selecting the Top N records in an Oracle Query
Document Actions

Selecting the Top N records in an Oracle Query

by antonh last modified 13-Oct-03 08:41 PM

In M$ Access, you can do this:: SELECT TOP 5 * FROM MYTABLE Not in Oracle. In Oracle, it's a bit more complicated...

In Oracle, you use a subquery, and the rownum value.

For example, if you want to find the top 10 earners in your company then do something like this:

 select * from (
  select empno,sal,rownum
  from emp
  order by sal desc
 )
 where rownum < 11 

 


This site conforms to the following standards: