dimanche 1 mars 2015

Get random row from MySQL table

I'm trying to fetch a random row from a table in MySQL. I'm using the following query:



SELECT *
FROM my_table
WHERE id IN (
SELECT ROUND((RAND() * (MAX(id)-MIN(id)))+MIN(id)) AS id
FROM my_table
);


I wish to understand why that query sometimes returns more than 1 row when the inner query always get 1 row?


Thanks





Aucun commentaire:

Enregistrer un commentaire