Skip to content

Instantly share code, notes, and snippets.

@arodbits
Last active October 14, 2016 16:32
Show Gist options
  • Save arodbits/f1fcfed9a5c70c7fb2c4dc8f138ea16c to your computer and use it in GitHub Desktop.
Save arodbits/f1fcfed9a5c70c7fb2c4dc8f138ea16c to your computer and use it in GitHub Desktop.
Update a field value on a MYSQL table by using a conditional subquery. Replace the occurrence of a character with a new one.
-- update any occurrence of a quote character from a string in mysql
update site_user as original
join (select site_user.id, replace(site_user.email, "\"", "") as new_email from site_user where email like "%\"%") as conditional
on original.id = conditional.id
set original.email = conditional.new_email;
--follow me on twitter: www.twitter.com/anthonyrod4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment