mysql中You can't specify target table for update in FROM clause错误
wengsy_5041的博客通过本文主要向大家介绍了mysql,sql等相关知识,希望本文的分享对您有所帮助
mysql中You can’t specify target table for update in FROM clause错误意思你不可以对某个表现进行select,然后根据select出来的值再进行操作。比如:
update tbl t
set 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 t
set 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了