Reputation: 8992
so suppose there's a table:
id column1 column2
1 333 4444
Where id is a primary key
And then I do
REPLACE INTO table (id, column2) VALUES (1, 55)
This will cause column1 to become null...is there a way to specify the query such that it will leave whatever existing value of column1 is when REPLACE matches an existing entry?
Upvotes: 2
Views: 439
Reputation: 83
According to MySQL docs, no you can't. But you can INSERT ... on DUPLICATE KEY UPDATE.
Upvotes: 1
Reputation: 126015
Use INSERT ... ON DUPLICATE KEY UPDATE
:
INSERT INTO table (id, column2) VALUES (1, 55)
ON DUPLICATE KEY UPDATE column2 = VALUES(column2)
Upvotes: 3