How to select a random record from MySQL database?

I am using the following query to select 1 random entry -

SELECT name FROM table WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM table ) ORDER BY id LIMIT 1

      

but it gives me the same recordset every time I call it. How can I improve random recording?

+2


a source to share


1 answer


Try the following:



SELECT * FROM tableName ORDER BY RAND() LIMIT 1

      

+4


a source







All Articles