Rob Ferguson
Rob Ferguson

Reputation: 1

How do I find/replace in MySQL

How do I find/replace all the values in one table1.field3 that match another table2.field2, using a loop of of table2.field2 that are like a wild card string Matching in table1.field1

Something like this.

    UPDATE productsTable.color
SET x = (
    SET productsTable.Color = colorstable.`name`

WHERE productsTable.ShortDescription LIKE colorstable.%`nameOfColor`%';
)

Upvotes: 0

Views: 44

Answers (1)

Cyclonecode
Cyclonecode

Reputation: 29991

You should be able to achive this without using a loop:

UPDATE productsTable, colorstable
  SET productsTable.color = colorstable.name
WHERE productsTable.shortdescription LIKE CONCAT('%',colorstable.name,'%');

Upvotes: 1

Related Questions