从 mysql 中随机抽取 1000 行(不是重复行)的最佳方法是什么?

What is the best way to random 1000 row (not duplicate row) from mysql?

从 mysql 随机抽取 1000 行(非重复行)的最佳方法是什么?

Now i use this
1. get all data(id row) in to array.
2. Random position of array 1000 position.
3. i will get 1000 row (not duplicate row)

但是,这个过程非常缓慢,

你有简单的方法来随机获取 1000 行(不是重复行)吗?

好吧,从评论来看,您对理论上的答案也很满意。

如果您的数组包含所有行,请使用 array_unique() to get rid of duplicate rows then use shuffle() to mix them up and at the end you can take a slice with array_slice()

编辑:

如果您已经不 select 重复行,则可以改进它,这样您就不必使用 array_unique()。为此使用 DISTINCT。如果您想在查询中完成所有操作,您可以这样做:

SELECT DISTINCT column FROM table
ORDER BY RAND()
LIMIT 1000