Results 1 to 5 of 5
  1. #1
    Join Date
    May 2009
    Posts
    3

    Unanswered: How to Get the Highest three earners from emp table?

    How to Get the Highest three earners from emp table?

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    One way would be to call them all, write down their salaries and sort them manually. Another one might be researching options described in How does one select the TOP N rows from a table?.

  3. #3
    Join Date
    Nov 2003
    Posts
    2,932
    Provided Answers: 12
    You need to use a SELECT statement

  4. #4
    Join Date
    May 2009
    Posts
    1
    SQL> select * from ( select ename, sal, row_number() over(order by sal desc ) rn from emp )where rn <=3 ;

    ENAME SAL RN
    ---------- ---------- ----------
    KING 5000 1
    SCOTT 3630 2
    JONES 3272 3

    Sanj
    b logspot
    http://db-oracl. b l o g s p o t .com/
    Last edited by sanj11; 05-12-09 at 13:47.

  5. #5
    Join Date
    Dec 2003
    Posts
    1,074
    Follow the link above, & determine if you want RANK or DENSE_RANK (if you're at a version which can use Analytic Functions). Based on the actual question you're asking, it makes a difference. I bet you're really looking for DENSE_RANK in this situation, which the above post doesn't give you.

    If you, in fact, are just looking for RANK, then the above SQL will actually give you the same results.

    --=Chuck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •