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?
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 http://dev.mysql.com/doc
according to the dox, that's per client....i need the LAST # period, no matter who made it....MANY clients here
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 UserID....do i need to include it somehow in that statement?