MySQL 中 You can't specify target table '表名' for update in FROM clause错误解决办法

背景

在MySQL中,写SQL语句的时候 ,可能会遇到 You can't specify target table '表名' for update in FROM clause 这样的错误

错误含义

它的意思是说,不能先 select 出同一表中的某些值,再 update 这个表(在同一语句中),即不能依据某字段值做判断再来更新某字段的值。

解决问题

将select出的结果再通过中间表select一遍,这样就可以解决错误了

原文地址:https://www.cnblogs.com/poloyy/p/12308353.html