Home > Blockchain >  Set random name to all entries of a table
Set random name to all entries of a table

Time:06-15

I've got a table with a list of contacts (about 1000) I would like to change every name of this contacts table with a random name pick from an anonymous table (100 random names, firsnames...)

I tried this request but every contact have the same name picked up from my anonymous table :

UPDATE contacts, anonymes
SET contacts.nom = anonymes.nom
WHERE anonymes.id_anonyme = ROUND(RAND()*99) 1;

Do you what I could do to update every name of my contacts table with a different random name from anonymous ?

CodePudding user response:

That's where the ORDER BY RAND() clause comes in.Try this:

UPDATE contacts
SET nom = (select nom from anonymes order by rand() limit 1)
;
  • Related