mysql中You can't specify target table for update in FROM clause错误

来源:互联网 发布:淘宝特卖网qitemei 编辑:程序博客网 时间:2024/05/29 16:25

mysql中You can’t specify target table for update in FROM clause错误意思你不可以对某个表现进行select,然后根据select出来的值再进行操作。比如:

update tbl tset t.name = 'xxx'where id in (        select max(id) from tbl a where EXISTS        (            select 1 from tbl b where a.tac=b.tac group by xx         )        group by xx)

解决方案是对select出来的结果进行一次包装:如下

update tbl tset t.name = 'xxx'where id in (    select * from (        select max(id) from tbl a where EXISTS        (            select 1 from tbl b where a.tac=b.tac group by xx        )        group by xx        ) tmp)

这样就ok了

阅读全文
0 0