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. How to select records 11 to 20 in SQL SERVER?

How to select records 11 to 20 in SQL SERVER?

Scheduled Pinned Locked Moved Database
databasemysqlsql-serversysadmintutorial
7 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.
  • P Offline
    P Offline
    pankazmittal
    wrote on last edited by
    #1

    Hi I want to select records 11 to 20 in sql server. In MySQL this is how it is done. How can we do it in SQL SERVER 2005 and above? SELECT * FROM employees LIMIT 10,10; In MySQL, LIMIT x,y means skip the first x records, and then return the next y records. Thanks Pankaj

    G B N 3 Replies Last reply
    0
    • P pankazmittal

      Hi I want to select records 11 to 20 in sql server. In MySQL this is how it is done. How can we do it in SQL SERVER 2005 and above? SELECT * FROM employees LIMIT 10,10; In MySQL, LIMIT x,y means skip the first x records, and then return the next y records. Thanks Pankaj

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

      You need to use ranking function which are available in microsoft sql server.

      Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

      1 Reply Last reply
      0
      • P pankazmittal

        Hi I want to select records 11 to 20 in sql server. In MySQL this is how it is done. How can we do it in SQL SERVER 2005 and above? SELECT * FROM employees LIMIT 10,10; In MySQL, LIMIT x,y means skip the first x records, and then return the next y records. Thanks Pankaj

        B Offline
        B Offline
        Blue_Boy
        wrote on last edited by
        #3

        select top 10 from employees where id between 11 and 20


        I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

        P 1 Reply Last reply
        0
        • B Blue_Boy

          select top 10 from employees where id between 11 and 20


          I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

          P Offline
          P Offline
          pankazmittal
          wrote on last edited by
          #4

          what is id here in your select? Basically, what I am looking for is to select rows paging like functionality. I don't want to bind any table column in select.

          B 1 Reply Last reply
          0
          • P pankazmittal

            what is id here in your select? Basically, what I am looking for is to select rows paging like functionality. I don't want to bind any table column in select.

            B Offline
            B Offline
            Blue_Boy
            wrote on last edited by
            #5

            ID supposed to be column name of your table Employee.I used name ID of column but it may be different name.


            I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

            1 Reply Last reply
            0
            • P pankazmittal

              Hi I want to select records 11 to 20 in sql server. In MySQL this is how it is done. How can we do it in SQL SERVER 2005 and above? SELECT * FROM employees LIMIT 10,10; In MySQL, LIMIT x,y means skip the first x records, and then return the next y records. Thanks Pankaj

              N Offline
              N Offline
              Niladri_Biswas
              wrote on last edited by
              #6

              It is pretty simple in SQL SERVER 2005 (onwards) too. Use ROW_NUMBER() function. I have a table(say CHOOSERECORDS) with only 1 column(say RECORDS) of type int(Created for answering you question only) Now I have inserted values from 1 to 100 there. Next I want to select records from say 11 to 20. The query is here

              SELECT A.RECORDS FROM (SELECT ROW_NUMBER() OVER (ORDER BY RECORDS) AS ROWID,RECORDS FROM CHOOSERECORDS) A
              WHERE A.ROWID BETWEEN 11 AND 20

              Hope this answers your question. Vote me please :)

              Niladri Biswas

              P 1 Reply Last reply
              0
              • N Niladri_Biswas

                It is pretty simple in SQL SERVER 2005 (onwards) too. Use ROW_NUMBER() function. I have a table(say CHOOSERECORDS) with only 1 column(say RECORDS) of type int(Created for answering you question only) Now I have inserted values from 1 to 100 there. Next I want to select records from say 11 to 20. The query is here

                SELECT A.RECORDS FROM (SELECT ROW_NUMBER() OVER (ORDER BY RECORDS) AS ROWID,RECORDS FROM CHOOSERECORDS) A
                WHERE A.ROWID BETWEEN 11 AND 20

                Hope this answers your question. Vote me please :)

                Niladri Biswas

                P Offline
                P Offline
                pankazmittal
                wrote on last edited by
                #7

                Thanks Niladri. Exactly what I was looking for.

                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