How to get latest ID number in a table?

后端 未结 7 1864
日久生厌
日久生厌 2021-01-22 00:58

How can I get the latest ID in a table?

相关标签:
7条回答
  • 2021-01-22 01:48

    If the table has an auto_increment column defined - you can check by looking for "auto_increment" in the output from DESC your_table, use:

    mysql_insert_id
    

    Otherwise, you have these options:

    SELECT MAX(id) FROM your_table
    SELECT id FROM your_table ORDER BY id LIMIT 1
    
    0 讨论(0)
提交回复
热议问题