简体   繁体   English

如何获取非自动递增ID中的最后一个值?

[英]how to get the last value in the non auto incremented id?

I am using two IDs DM_ID and id. 我正在使用两个ID DM_ID和ID。 DM_ID is auto incremented while id is not. DM_ID自动增加,而id不自动增加。 I want to get the last value of id. 我想获取id的最后一个值。 I used mysqli_insert_id() to get it but i get the last of DM_ID. 我使用mysqli_insert_id()来获取它,但我得到了DM_ID的最后一个。 DM_ID and is in one table. DM_ID,位于一个表中。

You need to fire a query to get that, 您需要执行查询才能获取该信息,

SELECT MAX(`id`) from `tbl_name`

Or if you need id of last inserted record, 或者,如果您需要最后插入的记录的id

SELECT `id` from `tbl_name` where `DM_ID` = mysqli_insert_id()

这样尝试

   select id from tablename order by DM_ID desc limit 1
SELECT id from tablename order by DM_ID desc limit 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用medoo获取最后一个自动增加的id - get the last auto incremented id with medoo 如何从数据库获取自动递增的ID值 - How to get auto incremented id value from database 我如何在控制器内的 Laravel 的不同表中获取自动递增 id 的值作为外键 - how can i get the value of an an auto incremented id as a foreign key in a different table in Laravel inside a controller 如何获取最新的自动递增ID的数组? - how to get array of latest auto incremented id's? 使用codeigniter,并且需要使用oci8获取下一个查询的上一个自动递增的ID的ID - using codeigniter and need to get id of last auto-incremented id for next query, using oci8 如何获得自动递增的字段 - How to get auto incremented field 将信息分配给表并创建自动递增的ID…如何获取该新创建的ID? - Assigning info to a table and creating an auto incremented id… How to get that newly created id? 使用php插入值后,如何获取行的自动递增ID? - How to get the auto-incremented ID for a row once you insert values using php? 创建具有年份和自动递增值的学生ID编号 - create Student ID number with year and auto incremented value 创建由当前年份数字和自动递增值组成的唯一ID - Create a unique ID composed of the current year number and an auto incremented value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM