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
  • 104,438
  • 178
  • 489
  • 842

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,242,037
  • 58
  • 646
  • 786