Skip to content

Instantly share code, notes, and snippets.

@locvfx
Last active November 19, 2018 03:10
Show Gist options
  • Save locvfx/b3faf3cac6d894c7fd345cc694ea3f1c to your computer and use it in GitHub Desktop.
Save locvfx/b3faf3cac6d894c7fd345cc694ea3f1c to your computer and use it in GitHub Desktop.
SQLl to select random record in huge data table #SQL
SELECT `post_title` FROM bf_article_posts AS r1 JOIN (SELECT CEIL(RAND() * (SELECT MAX(id) FROM bf_article_posts)) AS id) AS r2 WHERE r1.id >= r2.id ORDER BY r1.id ASC LIMIT 10
#https://stackoverflow.com/questions/4329396/mysql-select-10-random-rows-from-600k-rows-fast
#http://jan.kneschke.de/projects/mysql/order-by-rand/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment