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 for last rows

SQL Query for last rows

Scheduled Pinned Locked Moved Database
databasequestion
5 Posts 2 Posters 18 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hello, I can't find an elegant solution for the following using ASP2.0 with MS SQL 7.0 SP2: I would like to select the last 10 rows of a query without using RecordSet.MovePrevious nor using FETCH anyone has an idea ? Thanks, Steven:confused:

    L L 2 Replies Last reply
    0
    • L Lost User

      Hello, I can't find an elegant solution for the following using ASP2.0 with MS SQL 7.0 SP2: I would like to select the last 10 rows of a query without using RecordSet.MovePrevious nor using FETCH anyone has an idea ? Thanks, Steven:confused:

      L Offline
      L Offline
      l a u r e n
      wrote on last edited by
      #2

      if you have a key that can be used for a sort order (ORDER BY) then you can say something like: SELECT TOP 10 whatever FROM whatever ORDER BY key DESC it will give the first 10 items entered into the table, ie, the bottom 10 of the recordset :) --- "every year we invent better idiot proof systems and every year they invent better idiots"

      L 1 Reply Last reply
      0
      • L l a u r e n

        if you have a key that can be used for a sort order (ORDER BY) then you can say something like: SELECT TOP 10 whatever FROM whatever ORDER BY key DESC it will give the first 10 items entered into the table, ie, the bottom 10 of the recordset :) --- "every year we invent better idiot proof systems and every year they invent better idiots"

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

        Thanks Lauren, I figured that out myself too :) The problem is that I want the last ten rows displayed in ascending order without having to use RecordSet.Previous. The recordset should contain the last ten rows (I know the value of last item in the table regarding to the query) in ascending order so I can display them using while vRS.EOF = False Then vRs.MoveNext ...and I don't want to swim through a big recordset using FETCH... any ideas ? Thanks, Steven

        L 1 Reply Last reply
        0
        • L Lost User

          Thanks Lauren, I figured that out myself too :) The problem is that I want the last ten rows displayed in ascending order without having to use RecordSet.Previous. The recordset should contain the last ten rows (I know the value of last item in the table regarding to the query) in ascending order so I can display them using while vRS.EOF = False Then vRs.MoveNext ...and I don't want to swim through a big recordset using FETCH... any ideas ? Thanks, Steven

          L Offline
          L Offline
          l a u r e n
          wrote on last edited by
          #4

          are you processing the results on the server before display? if so you could do the previous suggestion and simply run a flip algorithm on the results set in memory reasons like this stop me using recordset objects :) --- "every year we invent better idiot proof systems and every year they invent better idiots"

          1 Reply Last reply
          0
          • L Lost User

            Hello, I can't find an elegant solution for the following using ASP2.0 with MS SQL 7.0 SP2: I would like to select the last 10 rows of a query without using RecordSet.MovePrevious nor using FETCH anyone has an idea ? Thanks, Steven:confused:

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

            Hello, Maybe this will help you. SELECT a.member_no FROM adult AS a WHERE a.member_no IN (SELECT TOP 10 b.member_no FROM adult AS b ORDER BY b.member_no desc) ORDER BY a.member_no It's not elegant. It works!! Edwin. :cool:

            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