首页 > 技术文章 > Mysql - You can't specify target table '表名' for update in FROM clause 错误解决办法

poloyy 2020-02-14 17:58 原文

背景

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

错误含义

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

 

解决问题

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

 

推荐阅读