LAST_INSERT_ID()
returns the id of the last inserted row and is not bound to any table. So if you create a new row:
INSERT INTO table VALUES('a', 'b', 'c');
It will return the last id (whatever value the new primary key has).
SELECT LAST_INSERT_ID();
=> 123
For details, please take a look at the manual:
LAST_INSERT_ID() (with no argument) returns a BIGINT (64-bit) value representing the first automatically generated value that was set for an AUTO_INCREMENT column by the most recently executed INSERT statement to affect such a column. For example, after inserting a row that generates an AUTO_INCREMENT value, you can get the value like this:
If you just want to get last ID in a table, you can do it like this:
SELECT id FROM table ORDER BY id DESC LIMIT 1;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…