用 nick='a' (在一个查询中)的最大 id 值更新记录的最快方法是什么?
我的表如下所示:
+------+--------+----+
| 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 子句中指定目标表“帖子”进行更新