且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果仅满足条件,如何使用 SQL 语法从 MySQL 表中选择最后一条记录

更新时间:2023-01-28 20:51:22

正常的方法是将结果按 DESC 顺序排序,并将结果集限制为 1 行

The normal method is to order the result in DESC order and LIMIT the result set to 1 row

SELECT Id, dept_id, mat_code, topic
WHERE dept_id = 'something'
ORDER BY Id DESC
LIMIT 1