You can’t specify target table ‘aaa′ for update in FROM clause
You can’t specify target table ‘aaa′ for update in FROM clause
使用MySQL 执行DELETE FROM时,若子查询的 FROM 子句和更新/删除对象使用同一张表,会出现错误。
针对“同一张表”这个限制,撇开效率不谈,多数情况下都可以通过多加一层SELECT别名表来变通解决,如下:
DELETE FROM aaa WHERE id IN (SELECT id FROM (SELECT aaa.id FROM aaa WHERE 1=1) tmp)
Copyright © 2024 Primzahl. All rights reserved.