S
S
SimBioT192015-09-25 10:00:14
MySQL
SimBioT19, 2015-09-25 10:00:14

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

How productive is it and is there a better replacement?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2015-09-25
@alexey-m-ukolov

Why don't you like it?

SELECT id, name
FROM table
WHERE status = 1 ORDER BY RAND() LIMIT 1

D
Dmitry Kim, 2015-09-25
@kimono

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 question

Ask a Question

731 491 924 answers to any question