开发者

random record from mysql table

Is there any built-in function except order by random() to select a random record in mysql table开发者_如何学C?


No, but you can make it into two questions. In pseudo-PHP-and-MySQL-code:

$max = SELECT COUNT(*) FROM example;
$rand = rand(0, $max-1);
SELECT * FROM example LIMIT $rand, 1;

The right way would probably be to make it into a stored procedure.


I don't think so... why don't you want to use the one that works?

BTW, I'm pretty sure it is ORDER BY RAND().

I've read it can be a performance problem on many rows... do you have many rows?


SELECT * FROM users ORDER BY RAND() Limit 0, 1;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜