1 Reply Latest reply on Apr 1, 2013 9:22 AM by 995974

    Query to display the nth highest paid employee

    934969
      Hi All,

      Can anybody explain this query?

      SELECT empno,ename,sal FROM emp X WHERE &N = (SELECT COUNT(DISTINCT sal) FROM emp WHERE sal >= x.sal);


      Thanks in Advance.....
      Dins
        • 1. Re: Query to display the nth highest paid employee
          995974
          HIi friend,
          This is a correalated subquery and the query will be processed like as below..


          for x in(select * from emp a)

          loop
          count the no of distinct salaries in emp such taht the sal is greater then or equal to x.sal
          if (that count <=n)
          then
          keep the record
          end if
          end loop

          Hope it will help.

          Regards
          Timir
          1 person found this helpful