0

I have a mysql table with usernames and their mail address. I want to update the values in usernames row to be the same as the mail address except the domain. For example, in [email protected] the user will be updated with "jondoe".

Is there any possibility to do this with a query?

0

1 Answer 1

1

Does this do what you want?

update t
    set username = substring_index(email, '@', 1);

I should note that different people can have the same email base name on different domains. So, you should be careful that you don't generate duplicates.

If that is a problem, then ask another question.

Sign up to request clarification or add additional context in comments.

3 Comments

This query gave me a syntax error. I changed all the names for the ones corresponding to my tables and fields.
@manuel, Gordon Linoff will not achieve clairvoyance until he reaches 500k points. What if you told us what that error actually was? That would make it easier to help you. Was the error possibly ERROR 1062 (23000): Duplicate entry...? :-) ).
@isemi . . . The error was stupid. I left out the third argument to substring_index(), and it is now fixed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.