【发布时间】:2011-06-25 02:35:07
【问题描述】:
最快的方法是什么 更新具有最大 id 值的记录,其中 nick='a'(在一个查询中)?
我的桌子是这样的:
+------+--------+----+
| nick | post | id |
+------+--------+----+
| a | tehe | 1 |
| a | tehe 2 | 2 |
| a | tehe 3 | 3 |
| b | omg | 4 |
| b | omg 2 | 5 |
| a | tehe 4 | 6 |
| b | omg 3 | 7 |
+------+--------+----+
我试过了:
update (select * from posts where nick='a' order by id limit 1) as last_id set post='tehe 4 updated';
但是UPDATE的目标表last_id是不可更新的 现在我知道它不应该起作用。
update posts set post = 'tehe 4? updated' where id = (select id from posts where nick='a' order by id desc limit 1);
但您不能在 FROM 子句中指定目标表 'posts' 进行更新
【问题讨论】: