我这样写不对吗?update a set number=number+1 where id=(select max(id) from a where pid=2)
报错:you can't specify target table 're' for update in from clause
怎么写??
...全文
628打赏收藏
关于update语句的问题
假如有一个表a。a中有id,pid,num三个属性,都是int类型的。 我想修改num的值 条件是,pid=2并且id最大 我这样写不对吗?update a set number=number+1 where id=(select max(id) from a where pid=2) 报错:you can't specify target table 're' for update in from clause 怎么写??
[Quote=引用 1 楼 iihero 的回复:]
改成这种形式
mysql> update a12 set num=num+1 where id = (select max(id) from (select id from a12 t where pid=2) t);
Query OK, 1 row affected (0.06 sec)
[/Quote]
正解。。顶一个。。
[Quote=引用 1 楼 iihero 的回复:]
改成这种形式
mysql> update a12 set num=num+1 where id = (select max(id) from (select id from a12 t where pid=2) t);
Query OK, 1 row affected (0.06 sec)
[/Quote]