1

(1 つのクエリで) 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 句で更新対象のテーブル 'posts' を指定することはできません

4

1 に答える 1

1
update posts
    set post = 'tehe 4 updated'
    where nick='a'
    order by id desc limit 1
于 2011-02-10T19:51:07.747 に答える