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. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
    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.