Results 1 to 4 of 4
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-15-2004 #1Just Joined!
- Join Date
- Oct 2004
- Posts
- 4
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?
thanks
- 10-15-2004 #2
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"Time is an illusion. Lunchtime, doubly so."
~Douglas Adams, The Hitchhiker's Guide to the Galaxy
- 10-15-2004 #3Just Joined!
- Join Date
- Oct 2004
- Posts
- 4
LAST_INSERT_ID()
LAST_INSERT_ID()
according to the dox, that's per client....i need the LAST # period, no matter who made it....MANY clients here
- 10-15-2004 #4Just Joined!
- Join Date
- Oct 2004
- Posts
- 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 UserID....do i need to include it somehow in that statement?
thanks again


Reply With Quote
