Skip to content

Instantly share code, notes, and snippets.

@jonpemby
Last active March 7, 2018 16:19
Show Gist options
  • Save jonpemby/a2da452914e7968aebaea8cb60d52939 to your computer and use it in GitHub Desktop.
Save jonpemby/a2da452914e7968aebaea8cb60d52939 to your computer and use it in GitHub Desktop.
MySQL random string from list
select elt(floor(1 + (rand() * @len)), "hello", "world", "this", "is", "a", "random", "list");
@jonpemby
Copy link
Author

jonpemby commented Mar 7, 2018

Edit

Fixed a NULL popping up - forgot to use FLOOR to keep random index within bounds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment