LAST_INSERT_ID

2023-10-24 09:23:03  Updated

Syntax

LAST_INSERT_ID()

Purpose

You can call this function to return the value of the last inserted auto-increment field in the current session.

If the last INSERT statement inserts multiple rows, LAST_INSERT_ID() returns the auto-increment field value of the first inserted row.

Examples

obclient> CREATE TABLE t1(c1 INT,c2 INT AUTO_INCREMENT);
obclient> SELECT LAST_INSERT_ID();
+------------------+
 LAST_INSERT_ID() 
+------------------+
                5 
+------------------+
1 row in set (0.00 sec)

Contact Us