开发者

How to select a random record from a MySQL database?

开发者 https://www.devze.com 2022-12-29 02:45 出处:网络
I am using the following query to select 1 ran开发者_运维技巧dom record - SELECT name FROM table WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM table ) ORDER BY id LIMIT 1

I am using the following query to select 1 ran开发者_运维技巧dom record -

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

but it gives me the same set of records every time I call it. How do I get better random record?


Try this:

SELECT * FROM tableName ORDER BY RAND() LIMIT 1
0

精彩评论

暂无评论...
验证码 换一张
取 消