MySQL 删除devices表中id最大的一行
原想法:delete from devices where id in (select max(id) from devices);
报错:ERROR 1093 (HY000): You can't specify target table 'devices' for update in FROM clause
网上查找原因说是:不能先select出同一表中的某些值,再update这个表(在同一语句中)
链接:https://blog.csdn.net/poetssociety/article/details/82391523
根据给出的解决方法优化为:
delete from devices where id in (select a.id from (select * from devices order by id desc limit 1) AS a );