原想法: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 );

 

相关文章:

  • 2022-12-23
  • 2022-02-12
  • 2022-01-05
  • 2022-12-23
  • 2021-11-23
  • 2021-06-30
  • 2022-12-23
猜你喜欢
  • 2022-01-22
  • 2021-12-04
  • 2021-06-03
  • 2022-12-23
  • 2022-02-28
  • 2021-07-27
  • 2022-12-23
相关资源
相似解决方案