THE WORLD'S LARGEST WEB DEVELOPER SITE

MySQL LAST_INSERT_ID() Function

❮ MySQL Functions

Example

Return the AUTO_INCREMENT id of the last row that has been inserted or updated in a table:

SELECT LAST_INSERT_ID();
Try it Yourself »

Definition and Usage

The LAST_INSERT_ID() function returns the AUTO_INCREMENT id of the last row that has been inserted or updated in a table.

Syntax

LAST_INSERT_ID(expression)

Parameter Values

Parameter Description
expression Optional. An expression

Technical Details

Works in: From MySQL 4.0

❮ MySQL Functions