How to get 5th Max value of salary in maximum

Discussion in 'MySQL' started by 50interviews, Feb 6, 2011.

  1. #1
    I have a mysql table with salary field in it. How to get 5th Max value of salary in maximum. Please help me regarding this
     
    50interviews, Feb 6, 2011 IP
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Rank the results by Salary in descending order and add a Limit at the end to only retrieve the 5th result (as first record is 0 then its LIMIT 4, 1; at the end of the statement)
     
    AstarothSolutions, Feb 7, 2011 IP
  3. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #3
    
    SELECT salary FROM table_name ORDER BY salary DESC LIMIT 5, 1
    
    Code (markup):
     
    mastermunj, Feb 7, 2011 IP
  4. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #4
    This will give you 6th record. It should be LIMIT 4,1 as suggested by AstarothSolutions.
     
    mwasif, Feb 7, 2011 IP
  5. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #5
    @mwasif, thanks! Don't know how I overlooked it.
     
    mastermunj, Feb 7, 2011 IP