Reputation: 3501
I'm trying to insert random values to tables. But I don't want to make new values totally random (like eg: random numbers or characters),I want to take a random value from a set of values defined earlier. For example: defined values: xyz, abc, edf random value: abc
I programming languages it's very easy, but in SQL I don't know, how to store this defined values and how to take random value.
Upvotes: 2
Views: 103
Reputation: 1269773
Put your random values in a table.
Then, you can insert them one at a time by doing:
insert into tables(val)
select val
from randomtable
order by rand()
limit 1
The order by rand() limit 1
chooses a random value from your list.
Upvotes: 2