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
You can use elt()
and random()
:
select id,
elt(floor(rand() * 3 + 1), 'microsoft', 'chrome', 'firefox') browser
from mytable;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With