Create table test(a int, c int);
Insert into test(a,c) values(1,3) on Duplicate key update c=c+1;
If you insert multiple rows of records (assuming A is a primary key or a is a unique indexed column):
Insert into test (a,c) values(1,3), (1,7) on duplicate key update c=c+1;
After execution, the value of C becomes 4 (the second is repeated with the first one, C is on the original value +1).
Insert into test (a,c) values(1,3), (1,7) on duplicate key update c=values(c);
After execution, the value of C changes to 7 (the second is repeated with the first one, and C is the value of the duplicate 7 directly).
This syntax and suitability is used in scenarios where it is necessary to determine whether a record exists or not, and the insert exists then update the scene
This article is from the "shallow poem Three line" blog, please be sure to keep this source http://3poetry.blog.51cto.com/11920015/1834283
MySQL duplicate key