简体   繁体   中英

SQL Update Table Where date = MIN(date)

I got the following code:

Update `Table` set amount='1003' WHERE date = (SELECT MIN(date)) AND `id` = 736

Something is wrong with my first Where rule date = (SELECT MIN(date)) but i dont know what.

You can update it from a join:

Update `Table` a
INNER JOIN (
    SELECT `id`, min(exp_date) AS exp_date from `Table` WHERE `id`= 736
) AS b ON (a.id=b.id AND a.exp_date=b.exp_date)
set amount='1003'
WHERE a.id = 736 AND a.exp_date=b.exp_date;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM