您的位置:首页 > 数据库 > MySQL

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

2017-08-07 14:55 585 查看
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了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql sql
相关文章推荐