Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update table with random values from given set of string values

Tags:

random

mysql

I want update my table with random values from given set, not from another table.

e.g. value1, value2, value3

and MySQL query should be update all records from above values.

I am looking similar type of solution but with random string values from given set: Update column with random value

like image 460
Rajnikanth Avatar asked Jun 24 '14 04:06

Rajnikanth


1 Answers

I would use the elt() function:

update tablename
    set columnname = elt(floor(rand()*3) + 1, 'value1', 'value2', 'value3');

elt() chooses a particular element from a list. rand() produces a random values.

like image 160
Gordon Linoff Avatar answered Oct 21 '22 14:10

Gordon Linoff