Skip to main content

Quick Tip: MySql Replace

While looking for ways to improve my MySQL queries, I can across the REPLACE function. This post shows are to use replace in INSERT, and UPDATE SQL queries.

Insert Statement

SELECT field1,
      REPLACE(stringVar, 'search for', 'string to replace with') AS field2,
FROM testdb

Update Statement

SET stringVar = REPLACE (stringVar, 'search for', 'string to replace with')
WHERE id=1