Returns the last AUTO_INCREMENT value generated for a column in the current connection.
BIGINT UNSIGNEDDiperbarui: 13 Jun 2026LAST_INSERT_ID([expr])Optional: set the value to be returned by subsequent calls
1 INSERT INTO users (name) VALUES ('John'); 2 SELECT LAST_INSERT_ID() AS new_user_id;
Retrieve the ID of the newly created user.
1 INSERT INTO orders (customer_id, total) VALUES (1, 100); 2 INSERT INTO order_items (order_id, product_id, qty) 3 VALUES (LAST_INSERT_ID(), 101, 2);
Insert into a related table using the foreign key from the previous insert.
1 SELECT LAST_INSERT_ID(1000) AS set_id; 2 -- Subsequent calls return 1000 3 SELECT LAST_INSERT_ID() AS current_id;
Set a custom value for the session.
Sudah paham LAST_INSERT_ID? Latih langsung di browser
Latihan interaktif, langsung di browser.