LAST_INSERT_ID
Syntax
LAST_INSERT_ID()
Description
Returns the value of the auto-increment column for the last inserted row in the current session.
In particular, if the most recent INSERT statement inserted multiple rows, LAST_INSERT_ID() returns the value of the auto-increment column for the first inserted row.
Examples
CREATE TABLE t1(c1 INT,c2 INT AUTO_INCREMENT);
SELECT LAST_INSERT_ID();
+------------------+
| LAST_INSERT_ID() |
+------------------+
| 0 |
+------------------+
1 row in set (0.001 sec)