I have the following MySQL query that pulls back 400 records:
SELECT email FROM user WHERE email LIKE 'GMSD%@law.com'
Returns:
[email protected] through [email protected]
What I want to do is remove the K from all 400 of these e-mail addresses in one easy UPDATE
, so the return would be [email protected] through [email protected].
How can I do this from a LIKE
query? Using RegEx somehow?
2
Answers
As the where clause only finds mails with GMSD at the start and @law.com at the end, you should not have any side effects
fiddle
if you have much more complicated emails, which doesn’t seemed to be in your example data, you can also use regular expressions, which actually only replaces the first occurrence of the search pattern, which the replace would replace also
fiddle
Your initial query seems… off:
Shouldn’t that be:
Also,
LIKE 'GMSD%@law.com'
should probably beLIKE 'GMSDK%@law.com'
, to capture values that actually have aK
in it.I would expect something simple, like using MySQL’s
REPLACE()
function should handle this:Edit: In my experience, table names are
plural
, sousers
instead ofuser
. If you are indeed usinguser
, adjust as required.