Got a big table and I want to add a column that has a randomly chosen number for each record. 1, 2, or 3.
Having a hard time. Any ideas?
Use RAND() function. It returns a random floating-point value v in the range 0 <= v < 1.0. To obtain a random integer R in the range i <= R < j, use the expression FLOOR(i + RAND() * (j − i + 1)). For example, to obtain a random integer in the range the range 1<= R < 3, use the following statement:
UPDATE tableName
SET ColumnName= FLOOR(1 + rand() * 3);
N.B : RAND() produces random float values from 0 to 1.