Hi ,

Can we have an sql query to get the max 5 values from a column?
Please paste a sample code if its possible.

Thanks in advance.

Got the soln, as below

select * from (select a from <tbl> order by a DESC) where rownum<=5;

Thanks.

select * from <tab> where rownum <=5
order by <a> desc.

I dont think extra subquery is needed here.
pls correct me if m wrong.

Yes buddy, the extra sub querry is needed, as in below case :

select * from <tab> where rownum <=5
order by <a> desc

the first 5 rown are getting sorted and then ordered, which would not essesntaily return max 5 values.

However if we use it as :

select * from (select a from <tbl> order by a DESC) where rownum<=5;

the results are first ordered in desceding order i.e max to lowest and on selecting the frist 5 rows, we get the 5 max values.

@ iceman

Thanx pal for correcting me

Excellent stuff mate... Thanks a ton!