Have the following problem
INSERT INTO statistics_new (SELECT * FROM statistics)
->
-> ON DUPLICATE KEY UPDATE
->
-> end_date = IF(end_date < VALUES(end_date), VALUES(end_date), end_date);
ERROR 1052 (23000): Column 'end_date' in field list is ambiguous
When I tried to specify column and table aliases as it recommended in http://dev.mysql.com/doc/refman/5.0/en/insert-select.html I had the same result.
Server version: 5.5.24-0ubuntu0.12.04.1 (Ubuntu)
The following query runs without problem :
INSERT INTO statistics_new (SELECT * FROM statistics)
ON DUPLICATE KEY UPDATE
end_date = VALUES(end_date)
SQLFiddle example
Basically I think you want this:
INSERT INTO statistics_new (SELECT * FROM statistics)
ON DUPLICATE KEY UPDATE
statistics_new.end_date = if(statistics_new.end_date < statistics.end_date,
statistics.end_date, statistics_new.end_date);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With