SQL更新表其中date = MIN(date)

时间:2016-10-21 08:21:33

标签: mysql sql min

我收到了以下代码:

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

我的第一个Where规则date = (SELECT MIN(date))出了点问题,但我不知道是什么。

1 个答案:

答案 0 :(得分:1)

您可以从加入中更新它:

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;