Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Top 10 in Oracle SQL

Status
Not open for further replies.

Larshg

Programmer
Mar 1, 2001
187
DK
Hi

Yousing Oracle SQL - I only want the 10 top rows
This is my sql sentence

select * from prepaid.rating_report
order by startdate desc;

Right now I spooling it to at file and the making a hedad -10 on it - it works but I would rather do it in SQL.

/Larshg
 
You'd use rownum - see thread186-172936
HTH
;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
You may try the following as well:

Select rownum,
cola,
colb
from Table1
where rownum < 11

AA :~)
 
Actually, rownum < 11 returns the first 10 rows returned by the query NOT the top 10 rows.

You have to wrap the ordered query in a 'select ... where rownum < N'.

Example:

select t0.*
from
(select *
from prepaid.rating_report
order by startdate desc) t0
where rownum < 11 ;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top