How to get the last inserted row ID in MySQL

kishore21
 
on Sep 08, 2016 01:33 AM
4614 Views

I want to get the last inserted ID when i insert the new data into the database help me with msql query

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Sep 08, 2016 01:40 AM
on Sep 08, 2016 01:42 AM

Hi kishore21,

If your ID is AutoIncrement Column. call LAST_INSERT_ID() function immediately after insertion.

SELECT LAST_INSERT_ID();

 

 

kishore21
 
on Sep 08, 2016 01:50 AM

No ID is not autoincrement column

dharmendr
 
on Sep 08, 2016 02:10 AM

While inserting the record are you inserting the ID serially or randomly?

If you are inserting serially then use MAX() function.

SELECT MAX(ID) FROM TableName