How to replace all instances of a particular value in a mysql database with another?

Posted by Joseph on Stack Overflow See other posts from Stack Overflow or by Joseph
Published on 2010-03-21T01:07:41Z Indexed on 2010/03/21 1:11 UTC
Read the original article Hit count: 504

Filed under:
|

I'm looking for a MySQL equivalent of what str_replace is for PHP. I want to replace all instances of one word with another, I want to run a query that will replace all "apples" with "oranges".

The reason why:

UPDATE fruits SET name='oranges' WHERE name='apples';

isn't going to work for my situation, is because I often times have multiple words in a table row separated by commas like: "apples, pears, pineapples". In this case I want just apples to be replaced by oranges and pear and pineapples to stay in tact.

Is there any way to do this?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about php