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. sql query

sql query

Scheduled Pinned Locked Moved Database
databasequestioncareer
10 Posts 6 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.
  • J Offline
    J Offline
    joindotnet
    wrote on last edited by
    #1

    I want to retrieve top 2 of maximum salary records.What wud be the qeury???:confused::confused::confused::confused::confused::confused::confused:

    M V L 3 Replies Last reply
    0
    • J joindotnet

      I want to retrieve top 2 of maximum salary records.What wud be the qeury???:confused::confused::confused::confused::confused::confused::confused:

      M Offline
      M Offline
      Meysam Mahfouzi
      wrote on last edited by
      #2

      If you've got only one table containing all salaries, your answer is as simple as this:

      SELECT TOP(2) Salary
      FROM TABLE
      ORDER BY Salary DESC

      _

      J 1 Reply Last reply
      0
      • M Meysam Mahfouzi

        If you've got only one table containing all salaries, your answer is as simple as this:

        SELECT TOP(2) Salary
        FROM TABLE
        ORDER BY Salary DESC

        _

        J Offline
        J Offline
        joindotnet
        wrote on last edited by
        #3

        Can u plz tell if I want to get minimum of top 2.

        G 1 Reply Last reply
        0
        • J joindotnet

          Can u plz tell if I want to get minimum of top 2.

          G Offline
          G Offline
          Giorgi Dalakishvili
          wrote on last edited by
          #4

          Order the records in ascending order and select top two :)

          Giorgi Dalakishvili #region signature My Articles / My Latest Article[^] / My blog[^] #endregion

          1 Reply Last reply
          0
          • J joindotnet

            I want to retrieve top 2 of maximum salary records.What wud be the qeury???:confused::confused::confused::confused::confused::confused::confused:

            V Offline
            V Offline
            vaseeem
            wrote on last edited by
            #5

            select top 2 salary from tbl_salary order by salary desc select top 2 salary from tbl_salary order by salary asc

            Errors are like Mini Skirts, shorter they get, more revealing they become.

            1 Reply Last reply
            0
            • J joindotnet

              I want to retrieve top 2 of maximum salary records.What wud be the qeury???:confused::confused::confused::confused::confused::confused::confused:

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Now I got a question for you; Imagine you want to retrieve the top 3 salary records. How would you go about and do that? :-D

              J 1 Reply Last reply
              0
              • L Lost User

                Now I got a question for you; Imagine you want to retrieve the top 3 salary records. How would you go about and do that? :-D

                J Offline
                J Offline
                joindotnet
                wrote on last edited by
                #7

                you din understand my question and now making fun of me.'minimum of top 2' means the lesser of the top 2 that is the second largest salary.Now if you are too smart tell this eddyvluggen.

                L 1 Reply Last reply
                0
                • J joindotnet

                  you din understand my question and now making fun of me.'minimum of top 2' means the lesser of the top 2 that is the second largest salary.Now if you are too smart tell this eddyvluggen.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  joindotnet wrote:

                  making fun of me

                  I was, wasn't I?

                  joindotnet wrote:

                  What wud be the qeury???

                  You just wanted someone to write a query for you, and someone did. Have you actually tried writing the query? If so, why didn't you post the piece that you already wrote?

                  J 1 Reply Last reply
                  0
                  • L Lost User

                    joindotnet wrote:

                    making fun of me

                    I was, wasn't I?

                    joindotnet wrote:

                    What wud be the qeury???

                    You just wanted someone to write a query for you, and someone did. Have you actually tried writing the query? If so, why didn't you post the piece that you already wrote?

                    J Offline
                    J Offline
                    joindotnet
                    wrote on last edited by
                    #9

                    I can write the queries by myself. I just wanted to know whether there is a simplification for it select min(salary) from (select top 2 salary from order by salary desc) By the way this place is for professionals not for people like u who r here to have fun.

                    L 1 Reply Last reply
                    0
                    • J joindotnet

                      I can write the queries by myself. I just wanted to know whether there is a simplification for it select min(salary) from (select top 2 salary from order by salary desc) By the way this place is for professionals not for people like u who r here to have fun.

                      L Offline
                      L Offline
                      leckey 0
                      wrote on last edited by
                      #10

                      I didn't know professionals could not have fun. If you ask an oversimple question or break the forum guidelines, you will get flamed.

                      Blog link to be reinstated at a later date.

                      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