MYSQL SELECT random on large table ORDER BY SCORE -
this question has answer here:
i have large mysql table 25000 rows. there 5 table fields: id, name, score, age,sex
i need select random 5 males order score desc
for instance, if there 100 men score 60 each , 100 score 45 each, script should return random 5 first 200 men list of 25000
order rand()
is slow
the real issue 5 men should random selection within first 200 records. help
so use subquery.. way putting rand() on outer query less taxing.
from understood question want 200 males table highest score... this:
select * table_name age = 'male' order score desc limit 200
now randomize 5 results this.
select id, score, name, age, sex ( select * table_name age = 'male' order score desc limit 200 ) t -- written `as t` or else call order rand() limit 5
Comments
Post a Comment