3

So basically what i'm trying to do is search inside a table called "product_description" find the row 'name' and inside name search for the string Energy.

Lets say i have a product called Energy drink from America. I know how to search for Energy and to replace it:

$sql = "UPDATE product_description SET name = REPLACE(name, 'Energy', 'Best Energy')";

Is there a way to search for Energy and replace America with Europe?

2
  • update ... set foo=replace(...) where foo like '%America%'? Commented May 7, 2015 at 14:36
  • 2
    In geopolitical terms, America cannot be replaced, not by Europe. That won't ever happen. Commented May 7, 2015 at 14:41

1 Answer 1

2

Just use a WHERE clause with LIKE:

UPDATE product_description
    SET name = REPLACE(name, 'America', 'Europe')
        WHERE name LIKE '%Energy%'
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.