MySQL and PHP look for a row in a table, but replace another row

So, basically I am trying to search inside a table named "product_description"

find a row 'name'

and inside a name search for a row Energy

.

Let's say I have a product called "Energy Drink" from America. I know how to look for Energy and replace it:

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

      

Is there a way to find energy and replace America

with Europe

?

+3


source to share


1 answer


Just use a WHERE clause with LIKE:



UPDATE product_description
    SET name = REPLACE(name, 'America', 'Europe')
        WHERE name LIKE '%Energy%'

      

+2


source







All Articles