I have a DB table that already has an existing value that I don’t need to touch. When I try to call my SQL like so:
my table currently looks like this:
id col1 col2
5 10
$sql = “INSERT INTO sometable (id, col2) VALUES (5, 20)
ON DUPLICATE KEY UPDATE id = 5”;
I would expect the table to look like this after my insert:
id col1 col2
5 10 20
Is there a way to accomplish this without using an update?
Assuming id is the key
This
Says to update the id field to 5 (
UPDATE ID =5). Which would only work if the ID was 5 and makes no senseWhat you want is either
Or if you want to reference the value it would have been if there was no duplicate then use as Wilken suggested
COL2 = VALUES(COl2)DEMO