Answer the question
In order to leave comments, you need to log in
Picking a random record from a db?
There is a working request code
SELECT id, name
FROM table
WHERE status = 1 ORDER BY MD5( CONCAT( ID, CURRENT_TIMESTAMP ) ) LIMIT 1
Answer the question
In order to leave comments, you need to log in
Why don't you like it?
SELECT id, name
FROM table
WHERE status = 1 ORDER BY RAND() LIMIT 1
Both options are very costly. It is done in 2 requests.:
The first request gets the number of records. The second one asks for what you need with a random offset offset.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question