Posted By

iroybot on 09/22/09


replace update where

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Conditional String Replace

 / Published in: MySQL

as a note to self... in order to find it laters...

This will only alter the value of fieldname if the conditions in the WHERE clause are met. With replace we only replace a certain string within fieldname with the replace_with string

  1. UPDATE `table` SET `table`.`fieldname` = REPLACE(`fieldname`, 'search_value', 'replace_with')
  2. WHERE `table`.`firstcondition_field` = 'firstcondition_value'
  3. AND `table`.`secondcondition_field` = 'secondcondition_value'
  4. AND so on...

Report this snippet  

You need to login to post a comment.