I have email addresses like user1@gmail.com, user2@ymail.com user3@hotmail.com … etc.
I want a Mysql SELECT that will trim user names and .com and return output as
gmail,ymail,hotmail, etc.
I have email addresses like user1@gmail.com , user2@ymail.com user3@hotmail.com … etc. I want a
Share
Assuming that the domain is a single word domain like gmail.com, yahoo.com, use
The inner
SUBSTRgets the right part of the email address after@and the outerSUBSTRING_INDEXwill cut off the result at the first period.otherwise if domain is expected to contain multiple words like
mail.yahoo.com, etc, use:LENGTH(email) - (INSTR(email, '@') + 1) - LENGTH(SUBSTRING_INDEX(email,'.',-1))will get the length of the domain minus the TLD(.com, .biz etc. part)by usingSUBSTRING_INDEXwith a negative count which will calculate from right to left.