MySQL: Get ID of the Last Updated Row

In this post, I demonstrate to get last updated ID of the last updated row in MySQL.
Whenever we are not updating row base on Primary key and updating row base of any other column data like: date, Name, at that time we require last updated id of the last updated row.

We should write update query such a way that we can get a last updated ID at the same time of update.
Here, I have provided different two way two ways to get a last updated ID of the last updated row.

Let’s first create a table with sample data.

First script to get a last updated ID:

Get all last updated ID when more than one row updates:

Second script using LAST_INSERT_ID():
Before this, please execute the insert script again.

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from

Sort by:   newest | oldest | most voted

Thanks Anvesh, You helped me lot. I am following you and interested in your articles and collections of DBA script.