Prepending a String to Column Values in MySQL
Problem:
You aim to modify a specific column in all rows of a MySQL table by adding a string ("test") to the beginning of the existing value. For instance, "try" would change to "testtry."
Solution:
Utilize the CONCAT function in an SQL update statement to achieve this:
UPDATE tbl SET col=CONCAT('test',col);
Advanced Update:
If you wish to selectively update only columns that do not already contain the "test" prefix, you can employ the following statement:
UPDATE tbl SET col=CONCAT('test',col) WHERE col NOT LIKE 'test%';
The above is the detailed content of How to Prepend a String to Column Values in MySQL?. For more information, please follow other related articles on the PHP Chinese website!