Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. query

query

Scheduled Pinned Locked Moved Database
databasetutorialcareer
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kjosh
    wrote on last edited by
    #1

    Hi, How to write a query to get 5th highest salary. Thanks in advance

    D A E 3 Replies Last reply
    0
    • K kjosh

      Hi, How to write a query to get 5th highest salary. Thanks in advance

      D Offline
      D Offline
      Dinuj Nath
      wrote on last edited by
      #2

      Select *,sal From Emp X Where 5 = ( Select Count(Distinct Sal) From Emp Where sal >=X.sal )

      R 1 Reply Last reply
      0
      • D Dinuj Nath

        Select *,sal From Emp X Where 5 = ( Select Count(Distinct Sal) From Emp Where sal >=X.sal )

        R Offline
        R Offline
        r stropek
        wrote on last edited by
        #3

        Hi! In SQL 2005 you should use CTE and the new ranking functions; write with EmpCTE ( EmpNo, ..., Sal, SalRank ) as ( select EmpNo, ..., Sal, dense_rank() over ( order by Sal desc ) ) select * from EmpCTE where SalRank=5; Rainer Stropek cubido business solutions gmbh Email r.stropek@cubido.at Visit my blog at http://www.cubido.at/Blog/tabid/176/BlogID/4/Default.aspx

        1 Reply Last reply
        0
        • K kjosh

          Hi, How to write a query to get 5th highest salary. Thanks in advance

          A Offline
          A Offline
          albCode
          wrote on last edited by
          #4

          select top 5 * from table order by salary desc

          1 Reply Last reply
          0
          • K kjosh

            Hi, How to write a query to get 5th highest salary. Thanks in advance

            E Offline
            E Offline
            Eric Dahlvang
            wrote on last edited by
            #5

            SELECT TOP 1 * FROM (SELECT TOP 5 salary FROM employees ORDER BY salary DESC) AS EMP ORDER BY salary ASC ---------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups