Mysql in PHP - how to update only one row in table but with greatest id number

前端 未结 9 2089

I am trying to update fields in my DB, but got stuck with such a simple problem: I want to update just one row in the table with the biggest id number. I would do something like

9条回答
  •  旧时难觅i
    2021-02-19 03:49

    Old Question, but for anyone coming across this you might also be able to do this:

    UPDATE
         `table_name` a
    JOIN (SELECT MAX(`id`) AS `maxid` FROM `table_name`) b ON (b.`maxid` = a.`id`)
    SET a.`name` = 'test_name';
    

提交回复
热议问题