You can't specify target table for update in FROM clause

来源:互联网 发布:exit code 0 python 编辑:程序博客网 时间:2024/06/17 00:02

今天使用mysql,写出一个sql语句:

 update service_re set is_deleted=0 where id=(select id from service_re where p_id=21000122321 limit 1);

执行这样的sql会报一个异常:

You can't specify target table  for update in FROM clause

查了资料,原来mysql不能那么用,mysql好愚蠢,为了实现这个目的,只能换一种写法:

update service_re set is_deleted=0 where id=(select b.id from(select a.id from service_re a where p_id=21000122321 order by gmt_create desc limit 1) b);
给原来where中的表起一个别名,然后再查询出来,总之,不能直接在where中使用需要update,insert,delete的表的名字。

0 0
原创粉丝点击