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. Selecting Rows

Selecting Rows

Scheduled Pinned Locked Moved Database
3 Posts 2 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.
  • S Offline
    S Offline
    sriharsha_12
    wrote on last edited by
    #1

    Say if i have 100 rows, if i need top 15 rows i'll use, select top 15 * from table1 if i need from row 25 to 50, how will i select!!!!

    M 1 Reply Last reply
    0
    • S sriharsha_12

      Say if i have 100 rows, if i need top 15 rows i'll use, select top 15 * from table1 if i need from row 25 to 50, how will i select!!!!

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      You can use row_number() over the sort field of your choice as a secondary query. In the following I have 1 select gets me the currencyID and the row number and joins that query to the select of the currency table. I can then filter of the RN field in the row_number query

      SELECT *
      FROM Currency C
      INNER JOIN
      (SELECT CurrencyID, ROW_NUMBER() OVER (ORDER BY CurrencyID) RN FROM currency) R
      ON R.currencyid = C.CurrencyID -- Join back to the currency table
      WHERE R.RN BETWEEN 6 AND 10

      Never underestimate the power of human stupidity RAH

      S 1 Reply Last reply
      0
      • M Mycroft Holmes

        You can use row_number() over the sort field of your choice as a secondary query. In the following I have 1 select gets me the currencyID and the row number and joins that query to the select of the currency table. I can then filter of the RN field in the row_number query

        SELECT *
        FROM Currency C
        INNER JOIN
        (SELECT CurrencyID, ROW_NUMBER() OVER (ORDER BY CurrencyID) RN FROM currency) R
        ON R.currencyid = C.CurrencyID -- Join back to the currency table
        WHERE R.RN BETWEEN 6 AND 10

        Never underestimate the power of human stupidity RAH

        S Offline
        S Offline
        sriharsha_12
        wrote on last edited by
        #3

        thanx man...i'll try that...

        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