Update table with random values from given set of string values

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.


Use floor(rand()*3) to generate a random number among 0, 1, and 2, then use case when to assign value

update test
set i = (case floor(rand()*3) 
         when 0 then 0 
         when 1 then 10 
         when 2 then 20 
         end);

fiddle

Tags:

Mysql

Random