help you fix your problem You need to be careful with MySQL. It's possible that VALUES(version)>version is using the updated version and not its original value. This differs from standard SQL and is mentioned here. Change the order of your assignments so that the test comes first.
like below fixes the issue I tried to do an INSERT without the "ON DUPLICATE KEY UPDATE" and MySQL responded with a helpful error that actually pointed to the REAL problem. It told me that the value I was inserting for the foreign key (Location) was a 'violation'. This was the case because there was no record in the Location table with key 0. I updated my sample insert to use a valid Location foreign key and that worked. The update succeeded. So in short, make sure you are inserting valid values! ;)
Mysql: On some duplicate column insert on all duplicate update
This might help you INSERT IGNORE and INSERT ... ON DUPLICATE KEY UPDATE are mutually exclusive. They both handle the situation when the row to be inserted conflicts with an already existing row on an UNIQUE INDEX. IGNORE converts the errors into warnings and this basically lets the query succeed and ignore the new values.
INSERT INTO Inventory VALUES('PA', 'Area 1', NOW(), NULL)
ON DUPLICATE KEY UPDATE
`In` = IF(ISNULL(`In`), VALUES(`In`), `In`),
`Out` = NULL
INSERT INTO... ON DUPLICATE KEY UPDATE not updating the duplicate value in PHP and mySQL
hop of those help? I'm trying to use the funcion INSERT INTO ... ON DUPLICATE KEY to insert some data in a mySQL table. And if there's already a user registered with the same email, i want to update the values. , The column email should be UNIQUE.