I want to use the "order by rand alternative" query (bottom) to get a random set of results but I want to get them from within the results a query such as:
SELECT t2.id FROM index_table t1 JOIN data_table t2 ON t1.id= t2.index_id
And I need to limit the number of random results I'd get back. I can't quite get my head around the syntax I'd need to use, any help greatly appreciated.
thanks
"order by rand alternative" query:
How can i optimize MySQL's ORDER BY RAND() function?
SELECT *
FROM (
SELECT @cnt := COUNT(*) + 1,
@lim := 10
FROM t_random
) vars
STRAIGHT_JOIN
(
SELECT r.*,
@lim := @lim - 1
FROM t_random r
WHERE (@cnt := @cnt - 1)
AND RAND(20090301) < @lim / @cnt
) i