1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Find Nth highest salary from table

Discussion in 'Databases' started by kamal_ce, May 23, 2008.

  1. #1
    TO find out 3rd highest salary from table

    --Find 3rd highest salary
    SELECT TOP 1 salary
    FROM (
    SELECT DISTINCT TOP 3 salary
    FROM tblSalary
    ORDER BY salary DESC) S
    ORDER BY salary


    General form to find to Nth highest salary from table

    --Find Nth highest salary
    SELECT TOP 1 salary FROM (
    SELECT DISTINCT TOP N salary FROM tblSalary ORDER BY salary DESC) S
    ORDER BY salary


    There are many solution to solve to this but above solution is easiest.
    Take other possible solution,

    SELECT MIN(salary) FROM tblSalary WHERE salary IN
    (SELECT DISTINCT TOP 3 salary FROM tblSalary ORDER BY salary DESC)
    --or--

    SELECT MIN(salary) FROM
    (SELECT DISTINCT TOP 3 salary FROM tblSalary ORDER BY salary DESC) S
     
    kamal_ce, May 23, 2008 IP
  2. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #2
    And what is the question ? Is this your homework ?
     
    it career, May 23, 2008 IP
  3. kashi

    kashi Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hi
    this is possible you can find the top-N salary by using this syntax:

    Select rownum as rank,salary
    from (select salary
    from table_name
    order by salary desc)
    where rownum is <=n;
     
    kashi, May 25, 2008 IP