Skip to content

Instantly share code, notes, and snippets.

@dennisdegryse
Created January 18, 2015 18:25
Show Gist options
  • Select an option

  • Save dennisdegryse/c24a78a21b3b81f1f3e6 to your computer and use it in GitHub Desktop.

Select an option

Save dennisdegryse/c24a78a21b3b81f1f3e6 to your computer and use it in GitHub Desktop.
Select ? random records
SELECT title
FROM table AS t1
JOIN (SELECT (RAND() * (SELECT MAX(id) FROM table)) AS id) AS t2
WHERE t1.id >= t2.id
ORDER BY t1.id ASC
LIMIT ?;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment