MENU

Find the Last inserted Auto increment ID in MYSQL with ASP

It’s taken me ages to find out how to do this (what turns out to be a) relatively simple operation.

Here’s the problem. Table 1 has a user_id which is auto incremented by MYSQL. Table 2 has an auto incremented login_id but also requires the user_id. Here’s how we get one ID from one table to the other:

objRS.source = “Select LAST_INSERT_ID() from Table1”
objRS.open
LastID = objRS(“LAST_INSERT_ID()”)
objRS.Close

Simple! We can then refer to the LastID in Table 2

Filed Under:

Subscribe to our mailing list

Join Hundreds of readers who have access to exclusive downloads and content

3 Responses

  • Mark says:

    “Could you not use MAX() to get the highest ID number?”

  • Katy says:

    “Could do, but if someone else was updating the recordset at the same time apparently it could get a bit screwey, there’s several ways of doing it.”

  • I have been surfing for mire than three hours today, and
    i’m yet to find a page like yours. It has made my effort online worth while.
    In my view, if all site owners andd bloggers
    prodcuced good content like this, the webb would
    be a ore useful resource.

Leave a Reply

Your email address will not be published. Required fields are marked *