When updating records, mysql must add new values on the original values.
For example, there was a record:
Id |
Country |
A784829a-c0dc-4cb6-88a9-8c376fab83a6 |
USA |
Update the country field now: Add "$ + $ UK" based on the original value to change it to the following value:
Id |
Country |
A784829a-c0dc-4cb6-88a9-8c376fab83a6 |
USA $ + $ UK |
However, when updating, you do not know the original value of the record, nor do you want to obtain the original value through mysql queries (in fact, you do not care about the original value, you only need to add a new value based on the original value ).
Finally, use the following SQL statement:
insert into video(id, country) values('a784829a-c0dc-4cb6-88a9-8c376fab83a6', 'USA') on duplicate key update country=CONCAT(country,values(country))
Bytes --------------------------------------------------------------------------------------------
Update:
If the original value is NULL, the preceding SQL statement cannot update the field value (but mysql does not report an error ).
Id |
Country |
A784829a-c0dc-4cb6-88a9-8c376fab83a6 |
NULL |
That is, after the preceding SQL statement is executed for the preceding records, the country value is NULL;
However, if the value is "" (NULL String) rather than NULL, the preceding SQL statement can run normally:
Id |
Country |
A784829a-c0dc-4cb6-88a9-8c376fab83a6 |
|
After the preceding SQL statement is executed, country = "USA ".
Conclusion: when creating table, you must specify this field not null and set default.