How is
SELECT t.id
FROM table t
JOIN (SELECT(FLOOR(max(id) * rand())) AS maxid FROM table)
AS tt
ON t.id >= tt.maxid
LIMIT 1
faster than
SELECT * FROM `table` ORDER BY RAND() LIMIT 1
I am actually having trouble understanding the first. Maybe if I knew why one is faster than the other I would have a better understanding.
*original post @ Difficult MySQL self-join please explain
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
SELECT
t_id
FROM
(SELECT
t.id AS t_id
FROM
table t LIMIT 1) t
JOIN
(
SELECT
(FLOOR(max(table.id) * rand())) AS maxid
FROM
table
) AS tt
ON t.t_id >= tt.maxid LIMIT 1