Reputation: 3374
I have a database table in MYSQL with around 1000 rows. In the table I have a column called 'overview'. In each row, this column has some value and at the end of that value I have a specific line (text) starting with: 'Source...'
Now what I want is, I want to remove this line from each column and replace it with some other text content.
I believe it can be accomplished with some smart query.
Upvotes: 1
Views: 104
Reputation: 16310
You can simply use REPLACE in your query like this
UPDATE your_table SET col_name = REPLACE(col_name , ‘Source...’, ‘new_val’)
WHERE col_name LIKE '%Source...';
Check Out the SQLFIDDLE.
Upvotes: 1
Reputation: 1457
you can do this by following:
update table_name set col_name = replace(column_name , ‘Source...’, ‘Replaced String...’);
Upvotes: 0
Reputation: 2133
Use Replace
update TBL set overview = Replace(picture, 'Source..', 'replacement')
keep a backup of the table before anything.Or you can do it on a copy.
Upvotes: 0
Reputation: 167250
MySQL database has a handy and simple string function REPLACE()
that allows table data with the matching string (from_string
) to be replaced by new string (to_string
).
The syntax of REPLACE
is:
REPLACE (text_string, from_string, to_string)
In your case, you can do this way:
UPDATE `tableName` SET `column` = REPLACE(column , 'Source...', 'Replaced Value')
Upvotes: 0