Get latest Identity value in MySQL?


In MySQL, We can get the last insert identity value by using the function LAST_INSERT_ID() .

Example :

Create table mysqlTable
(
  iId int AUTO_INCREMENT NOT NULL,
  First_Name varchar(100),
  Last_Name varchar(100)
);
Insert into mysqlTable(First_Name, Last_Name) 
Select 'Hitesh','Kumar' union
Select 'Dev','Yadav' union
Select 'Priyanka','Singla' union
Select 'Neha','Chauhan';


Query to get last inserted identity value

SELECT LAST_INSERT_ID() AS LastInsertedValue;


Result : 4