需求:想着更新id最大的一条数据:
原来的sql:
update work_plane_log_details SET `off_working_time`='2021-03-09 11:16:23'
WHERE id in (select id from work_plane_log_details where cardid='100ea' ORDER BY id desc limit 1 )
发现执行错误。
网上查找原因说是:不能先select出同一表中的某些值,再update这个表(在同一语句中)
优化后:
update work_plane_log_details SET `off_working_time`='2021-03-09 11:16:23'
WHERE id=(select a.id from (select * from work_plane_log_details where cardid='100ea' order by id desc limit 1) AS a )
标签:语句,log,update,plane,details,mysql,id,select From: https://blog.51cto.com/51souta/5805138