Sign up ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have a few variable data in the column "email".

For example:


How do I get rid of the characters after .com?

I used Replace(email,'.com%',, however, we cannot use wildcard characters in Replace.

Any Suggestions?

share|improve this question

2 Answers 2

    SUBSTRING(col, 1, CHAR_LENGTH(col) - CHAR_LENGTH( SUBSTRING_INDEX(col, '.com', -1) ) ) ;

If you want update the strings from a table, chopping off what is on the right of .com:

    col = SUBSTRING(col, 1, CHAR_LENGTH(col) - CHAR_LENGTH( SUBSTRING_INDEX(col, '.com', -1) ) ) 
    SUBSTRING_INDEX(col, '.com', -1) <> col ;
share|improve this answer

Does mysql have regular expressions? If so, maybe this points in the right direction

select regexp_replace ('roy2087@gmail.com123', '\.com.*','.com') email from dual;

works in Oracle, not sure about mysql.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.