KB‎ > ‎

SQL - Quick Reference 2

To select the to Top n rows in oracle SQL

select name, price
  from (
    select name, price, row_number() over (order by price) r
      from items
where r between 1 and 5;

select *
  from (
    select b.systemcode, b.lid  , a.STARTDATE, a.EVENTDESCRIPTION
      from sbyn_encounter a, sbyn_person b where b.LID='204997' and b.SYSTEMCODE='SFH' and a.PERSONID=b.personid and a.startdate is not null order by a.STARTDATE desc
where rownum <= 1;