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 the last inserted row

How To Select the last inserted row

Scheduled Pinned Locked Moved Database
tutorialquestion
5 Posts 3 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.
  • I Offline
    I Offline
    Iridania
    wrote on last edited by
    #1

    Hi, I would like to know how do i select the last inserted row in a table :sigh::confused: Thank you

    La Light

    P F 2 Replies Last reply
    0
    • I Iridania

      Hi, I would like to know how do i select the last inserted row in a table :sigh::confused: Thank you

      La Light

      P Offline
      P Offline
      Polymorpher
      wrote on last edited by
      #2

      Do you need to whole row or just the ID? You could try something like this for the whole row: SELECT * FROM tblSomething WHERE tblID = IDENT_CURRENT('tblSomething')

      Pablo Sometimes I think there's no reason to get out of bed . . . then I feel wet, and I realize there is.

      I 1 Reply Last reply
      0
      • I Iridania

        Hi, I would like to know how do i select the last inserted row in a table :sigh::confused: Thank you

        La Light

        F Offline
        F Offline
        Frank Kerrigan
        wrote on last edited by
        #3

        If the table has an Identity field (ID) or a created date field then this is fairly easy select top 1 * from table ORDER BY myfield DESC


        Blog Have I http:\\www.frankkerrigan.com

        I 1 Reply Last reply
        0
        • F Frank Kerrigan

          If the table has an Identity field (ID) or a created date field then this is fairly easy select top 1 * from table ORDER BY myfield DESC


          Blog Have I http:\\www.frankkerrigan.com

          I Offline
          I Offline
          Iridania
          wrote on last edited by
          #4

          But my Ids are uniqueidentifier so i cant not do it by a exacly field

          La Light

          1 Reply Last reply
          0
          • P Polymorpher

            Do you need to whole row or just the ID? You could try something like this for the whole row: SELECT * FROM tblSomething WHERE tblID = IDENT_CURRENT('tblSomething')

            Pablo Sometimes I think there's no reason to get out of bed . . . then I feel wet, and I realize there is.

            I Offline
            I Offline
            Iridania
            wrote on last edited by
            #5

            but when your ids are uniqueidentifiers you do have a the current id do you? and i'm not necersary selecting in the at the same time when the rows are selected.

            La Light

            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