The database is updated with the latest data

Filter according to the creation time create_time
The original data table
insert image description here

SQL command: find the latest piece of data of user "Sun", and update the password to 456
UPDATE power_user set password='456' where id=(SELECT id from power_user where user_name='Sun' ORDER BY create_time desc limit 1)

另一种方法:
UPDATE power_user set password=‘123’ FROM (SELECT * from power_user WHERE user_name=‘孙’ ORDER BY create_time desc limit 1) as t2 WHERE power_user.id=t2.id

The efficiency of the two methods is about the same.


insert image description here
The password and update time of the updated data sheet have been changed, and the modification is successful.

Guess you like

Origin blog.csdn.net/qq_41750806/article/details/118298778