Mysql 报错 You can‘t specify target table ‘表名‘ for update in FROM clause

翻译为:不能先select出同一表中的某些值,再update这个表(在同一语句中)

多半是update在where条件后又Select了一次,所以报错

SQL:

UPDATE a SET a.name = 1 WHERE a.id in (SELECT a.id FROM a WHERE ISNULL(a.id))

后面子查询再查询一次即可

UPDATE a SET a.name = 1 WHERE a.id in (SELECT * from (SELECT a FROM a WHERE ISNULL(a.see)) as b)

你可能感兴趣的:(mysql,数据库)