dongyishen5796 2015-08-01 18:44
浏览 252
已采纳

从mysql表中获取最后一个插入的ID

How to get the last inserted ID of a table, even if the last x record(s) have been deleted?

x can be 1 and can be like 200

  • 写回答

2条回答 默认 最新

  • duanhui7329 2015-08-01 23:24
    关注

    Assuming you're talking about auto incremented IDs:

    SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 'Table'
    

    This will give you the next increment id. To get the last inserted id just minus 1.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?