Sql - ON DUPLICATE KEY UPDATE
How do I update the entire row with this statement
INSERT INTO table (a,b,c) VALUES (1,2,3)
开发者_JAVA百科 ON DUPLICATE KEY UPDATE c=c+1;
But I want to update all fields besides the primary key which auto-increments. How?
Just add them to the second row like this:
INSERT INTO table (a,b,c) VALUES (1,2,3)
ON DUPLICATE KEY UPDATE c=c+1, b=b+3, ...
On multiple inserts at once, you can refer to the values like this:
INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6)
ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);
Have look at the Docs for more info on syntax.
精彩评论