Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    selecting last record

    i am new to MYSQL, so forgive the stupidity. actually worked with it years ago, but forgot most.

    anyway, i have a table, and the UserID column auto increments.

    and of course the only index i have is on THAT column.

    so AFTER inserting a NEW record, i want to go to the last RECORD and retireve that UserID as fast as possible.

    i know the whole "select UserID from TABLE"

    but how do i say WHERE LAST RECORD (google returns too many hits, can't find the right one)

    and do i need to specify the index?


  2. #2
    Linux Guru sarumont's Avatar
    Join Date
    Apr 2003
    The function LAST_INSERT_ID() will return the last auto-incremented value. You don't even have to run a select statement. Just assign a variable to the value that LAST_INSERT_ID() returns.

    For future reference, mysql has a great documentation section at
    "Time is an illusion. Lunchtime, doubly so."
    ~Douglas Adams, The Hitchhiker's Guide to the Galaxy

  3. #3



    according to the dox, that's per client....i need the LAST # period, no matter who made it....MANY clients here

  4. $spacer_open
  5. #4

    how's this

    right now am doing this:

    SELECT UserID from MyTable order by UserID DESC limit 1;

    now the ONLY index that exists on this table is on i need to include it somehow in that statement?

    thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts