Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
broshnat
· 13y ago · 0 comments
SELECT * FROM table ORDER BY RAND() LIMIT 10 ?
Comments
[–]
eurleif
13y ago
Try running EXPLAIN on that query. It has to create a temporary table, add a random column for every row, and then sort on that column. Not very fast.
[–]
broshnat
OP
13y ago
Ok, how about get the max ID and run a loop of 10 queries matching a random ID between 1 and maxID?
[–]
eurleif
13y ago
That's essentially what the top-voted answer does, except it accounts for gaps in the IDs.