Reputation: 110143
I am trying to create a mock dataset to test some queries on. How would I get a random selection from an array in mysql. For example:
select id, random(['microsoft', 'chrome', 'firefox']) browser from mytable
Upvotes: 4
Views: 3095
Reputation: 1269643
You can use elt()
and random()
:
select id,
elt(floor(rand() * 3 + 1), 'microsoft', 'chrome', 'firefox') browser
from mytable;
Upvotes: 11