Bug #60234 Last_insert_id()
Submitted: 24 Feb 2011 14:58 Modified: 24 Feb 2011 15:36
Reporter: Stefan Arhip Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Workbench: SQL Editor Severity:S3 (Non-critical)
Version:5.2.31 CE OS:Windows (XP SP3)
Assigned to: CPU Architecture:Any

[24 Feb 2011 14:58] Stefan Arhip
Description:
I try to retrieve the last insert id from a database.

How to repeat:
Select from `test`.`tphones` Last_insert_id()
[24 Feb 2011 15:13] Valeriy Kravchuk
Try something like this:

create table test.tai(id int auto_increment primary key);
insert into test.tai values ();
insert into test.tai values ();
select * from test.tai;
select last_insert_id();

Check the manual, http://dev.mysql.com/doc/refman/5.5/en/information-functions.html#function_last-insert-id, for the details.
[24 Feb 2011 15:21] Stefan Arhip
It's work, thank's, but only if I use right after insert statement.

But how to retrieve the biggest ID from a table. In this case, #3:

|----|
| ID |
|----|
|  1 |
|  2 |
|  3 |
|----|
[24 Feb 2011 15:34] Stefan Arhip
I got it! Thanks!
Here is the command:

Select id From test.tai Where id = (Select Max( id ) From test.tai);