Question : rownum

How can I get the row number for a record after filter by "WHERE" and sort by "ORDER" ?

Andrew

Answer : rownum

Here is an example using a subquery.


select * from emp
where empno = (select empno from
(select empno, sal, rownum as row# from (select empno, sal
from emp
group by sal,empno))
where row# = 3)

Here it sorts on the salary value and retreives the third value. If you want to do sort to find out the 3 max value use group by -sal, empno.

I am not too sure of the performance though.
Random Solutions  
 
programming4us programming4us