Conditional String Replace

/ Published in: MySQL
Save to your folder(s)

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

Copy this code and paste it in your HTML
  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


RSS Icon Subscribe to comments

You need to login to post a comment.