MySQL LAST_INSERT_ID() Function
THE WORLD'S LARGEST WEB DEVELOPER SITE

MySQL LAST_INSERT_ID() Function

❮ MySQL Functions

Example

Return the first AUTO_INCREMENT value that was set by the most recent INSERT or UPDATE statement:

SELECT LAST_INSERT_ID();
Try it Yourself »

Definition and Usage

The LAST_INSERT_ID() function returns the first AUTO_INCREMENT value that was set by the most recent INSERT or UPDATE statement.

Syntax

LAST_INSERT_ID(expression)

Parameter Values

Parameter Description
expression Optional. If expression is specified, the value is returned by LAST_INSERT_ID and remembered as the next value to be returned by the LAST_INSERT_ID() function

Technical Details

Works in: MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

❮ MySQL Functions