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. first three highest salaries

first three highest salaries

Scheduled Pinned Locked Moved Database
tutorialdatabasecareer
5 Posts 4 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.
  • C Offline
    C Offline
    chithra r
    wrote on last edited by
    #1

    hi all can anyone tell me how to (query to)find the first three highest salaries from a table. Example input Name Salary a 1000 b 5000 c 8000 d 11000 e 15000 f 2000 output: salary 15000 11000 8000 thanks in advance...

    pintoo

    T 1 Reply Last reply
    0
    • C chithra r

      hi all can anyone tell me how to (query to)find the first three highest salaries from a table. Example input Name Salary a 1000 b 5000 c 8000 d 11000 e 15000 f 2000 output: salary 15000 11000 8000 thanks in advance...

      pintoo

      T Offline
      T Offline
      Tripathi Swati
      wrote on last edited by
      #2

      select top 3 salary from tablename order by salary desc

      Reasons are not Important but Results are Important

      C 1 Reply Last reply
      0
      • T Tripathi Swati

        select top 3 salary from tablename order by salary desc

        Reasons are not Important but Results are Important

        C Offline
        C Offline
        chithra r
        wrote on last edited by
        #3

        hi thanks for answering..can u tell me how to write(modify) this query without using TOP keyword.

        pintoo

        W T 2 Replies Last reply
        0
        • C chithra r

          hi thanks for answering..can u tell me how to write(modify) this query without using TOP keyword.

          pintoo

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          I wonder why you don't want to use TOP, but here's another version:

          SELECT Name, Salary
          FROM TableName alias1,
          WHERE 4 < (SELECT COUNT(*)
          FROM TableName alias2
          WHERE alias2.Salary > alias1.Salary)

          Mika

          1 Reply Last reply
          0
          • C chithra r

            hi thanks for answering..can u tell me how to write(modify) this query without using TOP keyword.

            pintoo

            T Offline
            T Offline
            TheFM234
            wrote on last edited by
            #5

            I think that the Top will be the best choice, unless your using something other than SQL Server. If your using MySQl, use Limit 3 at the end of the statement.

            Select Salary
            From tablename
            Order By Salary Desc
            Limit 3

            I think any other method will cause overhang.

            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