Reputation: 1699
I have a column in my table named title_id with some title ids. Each title id is stored like
title_1
title_2
title_3
where 1, 2, 3 are the actual ids of the titles. I want to remove the " title_ " text from all the records. I have around 5000 records so I can't edit them manually.
How can I do it with a query.
Thanks in advance
Upvotes: 0
Views: 3191
Reputation: 1401
Try something like
update table_name set id=substring(id, from length('title_'))
where id like 'title%';
I didn't test this, because I have no MySQL DB available here. The syntax for the substring function is from the MySQL docs.
Upvotes: 1
Reputation: 13877
Check out the REPLACE
function. You can do something like:
UPDATE table
SET title_id = REPLACE(title_id, 'title_', '');
(Ah, and be sure to first test your UPDATE
query by running a SELECT
query!)
Upvotes: 1
Reputation: 6147
Update table_name set `title_id` = REPLACE(`title_id`,'title_','');
I didnt' tested it . Please check
Upvotes: 3