0

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;

9
  • Couldn't you just append the where clause to the end of your update? UPDATE `news` SET `details` = replace(details, 'image.GIF', 'new_image.GI') WHERE details LIKE '%image.GIF%' Commented Feb 17, 2016 at 21:22
  • Not sure I understand about what you want to do the column named 'title' which isn't present in your examples Commented Feb 17, 2016 at 21:26
  • You don't understand me correctly sorry. I want to rename related to details column entries in column title where matches image.GIF in details column! Commented Feb 17, 2016 at 21:28
  • @Ray I've added some explanation in question! Commented Feb 17, 2016 at 21:33
  • @amarullzamarullzz ok, so if you have a record with a detail named 'image.gif' you want to change the title column entries to new_image.gif of both the title and details columns? Commented Feb 17, 2016 at 21:41

1 Answer 1

2

Include the condition into a WHERE clause like

UPDATE `news`
 SET `title` = replace(title, 'image.GIF', 'new_image.GI')
WHERE details LIKE '%image.GIF%';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.