Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to remove everything before an '@' symbol in MySql Email column

Tags:

sql

mysql

I have a MySql data base with a 'user.email' field. I want to update the table to remove everything before the @ symbol so I am just left with a column of email domains. Can't seem to get me query to run. Any help is appreciated!

like image 903
Chris Avatar asked Nov 18 '14 18:11

Chris


3 Answers

Keep everything after '@'

UPDATE users SET email = SUBSTR(email,LOCATE('@',email) + 1)
WHERE LOCATE('@',email) > 0;

Keep everything starting '@'

UPDATE users SET email = SUBSTR(email,LOCATE('@',email))
WHERE LOCATE('@',email) > 0;
like image 134
RolandoMySQLDBA Avatar answered Oct 26 '22 13:10

RolandoMySQLDBA


Assuming your table name is USERS and has EMAIL as column

Before update your email column data would be like [email protected] [email protected]

update users SET email=replace(email,left(email, INSTR(email, '@')-1),'');

After update xyz.com syz.com

If you do not need the @ symbol in the domain then remove '-1' from the query

like image 28
Bharath Avatar answered Oct 26 '22 13:10

Bharath


Try this:

select right(email, charindex('@', reverse(email)) - 1)
like image 37
Gordon Linoff Avatar answered Oct 26 '22 14:10

Gordon Linoff