For better, better performance, use:
SELECT * FROM table WHERE id IN (SELECT id FROM table ORDER BY RANDOM() LIMIT x)
SQL engines first load the projected row fields into memory and then sort them , here we just randomly sort the id field of each row that is in memory because it is indexed and then separates X from them and find the entire row using these are X identifiers.
Thus, it reduces the amount of RAM and processor as the table grows!
Ali Jul 6 '14 at 12:29 a.m. 2014-07-06 00:29
source share