Jucain Jucain - 1 year ago 74
MySQL Question

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.

Answer Source

You can update it from a join:

Update `Table` a
    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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download