Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Change `table` to the name of your table, and tell me if there's a speed boost.
SELECT tab1.`id` FROM `table` AS tab1
JOIN
(SELECT
( RAND() * (SELECT MAX(id) FROM `table`) )
AS id )
AS tab2
WHERE tab1.id >= tab2.id
ORDER BY tab1.id ASC
LIMIT 1;
MySql does not have a normal random selection functionality. So use rand()
$rez = mysql_query("SELECT id from table")
$id = array_rand(mysql_fetch_array($rez))['id'];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question