4

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
David542
  • 101,766
  • 154
  • 423
  • 727

1 Answers1

10

You can use elt() and random():

select id,
       elt(floor(rand() * 3 + 1), 'microsoft', 'chrome', 'firefox') browser
from mytable;
Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709