Oracle Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yogendrapmishra
    New Member
    • Nov 2008
    • 1

    Oracle Query

    Hi,
    How can I fetch top 'n' salary from employ table? Please help me.
  • Pilgrim333
    New Member
    • Oct 2008
    • 127

    #2
    Hi,

    Try to use an order by in combination with a rowid smaller then...

    Pilgrim.

    Comment

    • amitpatel66
      Recognized Expert Top Contributor
      • Mar 2007
      • 2358

      #3
      Please post what you have tried so far so that we can help you in case of any problem

      Comment

      • ibrahim2008
        New Member
        • Nov 2008
        • 9

        #4
        Hi
        Just Try this query with RANK() Function,Enter Value for N and you'll get
        Top N salary and one thing for descending use NULLS LAST and for
        ascending use NULLS FIRST.But if u are omitting this NULLS FIRST or
        NULLS LAST,then for salary which is having null values,you'll get.

        Still using other queries you can also get top N salary like subqueries.

        SELECT Empno, Ename, Job, Mgr, Hiredate, Salary
        FROM
        (SELECT Empno, Ename, Job, Mgr, Hiredate, Salary,
        RANK() OVER
        (ORDER BY SALary Desc NULLS LAST) AS Emp_Rank
        FROM Emp
        ORDER BY SALary Desc NULLS LAST)
        WHERE Emp_Rank <N

        Regards,
        Ibrahim

        Comment

        • amitpatel66
          Recognized Expert Top Contributor
          • Mar 2007
          • 2358

          #5
          [code=oracle]
          SELECT * FROM(SELECT empname,empid,r ow_number() OVER(order by salary desc) rn from emp) WHERE rn = &n
          [/code]

          Comment

          Working...