开发者

2 Unique RAND() items from database

At present im using:

SELECT * from foo ORDER BY RAND() LIMIT 2

to select 2 random items from database but there is the possiblily of the result both being the sa开发者_如何学Gome item so how can i make it so they are not and both always different?

As always thanks in advance :)


Using ORDER BY RAND() does not result in duplicate rows.

Judging from scattered forum posts and bug reports, this might have been the case in a previous MySQL version (although I strongly doubt this), but it definitely is not anymore. I have just run a couple of tests myself and can confirm that ORDER BY RAND() should never return duplicate rows.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜