ama rullz amarullzz
ama rullz amarullzz

Reputation: 105

Select Find and replace query Mysql

How to figure out this query:

I want to find in column details where matches image.GIF with this query:

SELECT * FROM `news` WHERE details LIKE '%image.GIF%'

Then I have other column 'title' I want to rename these entries on 'title column' where related to above query.

UPDATE `news`
 SET `details` = replace(details, 'image.GIF', 'new_image.GI')

I hope It's understandable.

Column details - in this column to find all rows with text image.gif;

Column title - to rename all things inside to new_image.gif where belonging to details column;

Upvotes: 0

Views: 47

Answers (1)

Rahul
Rahul

Reputation: 77846

Include the condition into a WHERE clause like

UPDATE `news`
 SET `title` = replace(title, 'image.GIF', 'new_image.GI')
WHERE details LIKE '%image.GIF%';

Upvotes: 2

Related Questions