SQL Update Table Where date = MIN(date)

放肆的年华 提交于 2019-12-12 02:19:30

问题


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.


回答1:


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;


来源:https://stackoverflow.com/questions/40171682/sql-update-table-where-date-mindate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!