mysql update select 同一张表

来源:互联网 发布:淘宝高端是极限词吗 编辑:程序博客网 时间:2024/05/16 04:57

例如:

update from a表 where id in( select id from a表  where ......)

 mysql 会报 [Err] 1093 - You can't specify target table 'tc_cust' for update in FROM clause

MySQL手册UPDATE documentation这下面有说明 : “Currently, you cannot update a table and select from the same table in a subquery.”

解决方法:

1,创建临时表。(挺麻烦的。)

2,在in 字句 中 再用一层select 查询封装a表

update from a表 where id in( select id from (select id from a表  where ......) a1)

0 0
原创粉丝点击