4

I want to write a query that generates a number 1 - 1000 and inserts it into an email address, where that email is an empty string. I know the syntax is off, but can MySQL generate a random number that I can insert into a string to create an email such as [email protected]?

The update statement I'm looking for would be a query like this:

UPDATE contacts SET email = 'na@na' + random_number(1-1000) + '.com' WHERE email = ''; 
1
  • 1
    So this is where all the spam is coming from? foo123@, foo345@, etc? Commented May 7, 2017 at 3:21

1 Answer 1

7

I did this

 CONCAT("na@na", RAND() * 100 , '.com')
Sign up to request clarification or add additional context in comments.

3 Comments

combine it with ABS() to get rid of the float... CONCAT("na@na", ABS(RAND() * 100), '.com')
thanks i noticed that was an issue and i used CONCAT("na@na", ROUND(RAND() * 10000) , '.com')
I was using double concat, I did not know that I could put more than one string. Thanks for the answer !

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.