bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL References
SQL•SQL References

MySQL LAST_INSERT_ID() Function

Concept visual

MySQL LAST_INSERT_ID() Function

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

Example

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

SELECT LAST_INSERT_ID();

Definition and Usage

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

Syntax

LAST_INSERT_ID( expression )

Parameter Values

Parameter

Description expression

Optional. An expression

Technical Details

Works in:

From MySQL 4.0

Previous

❮ MySQL Functions

Next

Previous

MySQL ISNULL() Function

Next

MySQL NULLIF() Function