How to delete part of a MySQL database record?
I want to delete part of a record. For example, a column called "message" contains the following string:
"Hi, My name is John"
I want to delete just "John" from开发者_开发技巧 the above while retaining the "Hi, My name is" part in tact.
How can this be done?
You don't delete anything; the row is updated.
UPDATE table_name SET
message = "Hi, My name is"
WHERE message = "Hi, My name is John"
This would work:
UPDATE SomeTable SET message = REPLACE(message, "John", "") WHERE id = 123;
精彩评论