How do I update an email containing a double dot in its domain using raw mysql query?
So I have these emails having this format sample_email@gmail..com
and turn it to this sample_email@gmail.com
How do I update an email containing a double dot in its domain using raw mysql query?
So I have these emails having this format sample_email@gmail..com
and turn it to this sample_email@gmail.com
replace
should do the trick:
UPDATE mytable
SET email = REPLACE(email, '..', '.')
WHERE email LIKE '%..%'
You just need to use '%@%..%' as a like condition to extract all emails that have double dot on the domain. Then split the text by @, replace in the domain and concatenate the text.
select email
,concat(left(email,instr(email,'@')),replace(right(email,instr(reverse(email),'@')-1),'..','.')) new_email
from
(
select 'sample_email@gmail..com ' email
union
select 'sample..email@..foo.com'
union
select 'other..sample..mail..@foo..com..org'
) t
where email like '%@%..%'