@klopp , as far as I remember, RAND () in ORDER BY will be called for each line, i.e. if there are lots of records, RAND will be calculated, and then a lot of time will be spent on sorting.
@sergiks ,
SELECT DISTINCT tprice FROM ... $rand = array_rand( $tprices); SELECT `tid` FROM `tasks` WHERE `tprice` = $rand
Again, if there are a lot of records, then $ tprices will weigh a lot, and all entries will be selected for too long.
@ModaL , you can try:
SELECT COUNT(`tid`) AS CNT FROM `tasks` WHERE `tprice` BETWEEN 1 AND 3 $rand = rand(0, CNT); SELECT `tid` FROM `tasks` WHERE `tprice` BETWEEN 1 AND 3 LIMIT $rand, 1
Those. we get the number of records satisfying the condition, we get a random number ranging from 0 to the maximum, and then we select one element satisfying the condition from the position $ rand.
The only thing I do not know how will affect BETWEEN speed