thinkPHP 如何查询出数据库中id最大的一条数据?

如题所述

thinkPHP 查询数据库中id最大的一条数据操作如下:

    先给数据库中的这个字段(sort)分组 再降序排列, 取第1条。

    通过步骤1 获取了 sort值为最大的数据, 然后在 通过 where sort ='步骤1取的值'。

    查询最大ID,select max(id) from table。

    查询最大ID的记录 select * from table where id = (select max(id) from table)
    或者select * from table t where  not exists (select 1 from table t1 where t1.id > t.id)

温馨提示:内容为网友见解,仅供参考
第1个回答  2020-07-23
$max_info = Db::name('test')->order('id DESC')->findOrEmpty();
var_dump($max_info)
相似回答