I have the following MySQL query that pulls back 400 records:
SELECT email FROM user WHERE email LIKE 'GMSDemail@example.com'
GMSDK001@law.com through GMSDK400@law.com
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 GMSD001@law.com through GMSD400@law.com.
How can I do this from a
LIKE query? Using RegEx somehow?
Your initial query seems… off:
SELECT email FROM users WHERE user LKE ...
Shouldn’t that be:
SELECT email FROM users WHERE email LIKE ...
LIKE 'GMSDfirstname.lastname@example.org' should probably be
LIKE 'GMSDKemail@example.com', to capture values that actually have a
K in it.
I would expect something simple, like using MySQL’s
REPLACE() function should handle this:
UPDATE users SET email = REPLACE(email, 'GMSDK', 'GMSD') WHERE email LIKE 'GMSDKfirstname.lastname@example.org'
Edit: In my experience, table names are
users instead of
user. If you are indeed using
user, adjust as required.