quick selection of a random row from a large table in mysql

前端 未结 24 1731
旧时难觅i
旧时难觅i 2020-11-22 09:30

What is a fast way to select a random row from a large mysql table?

I\'m working in php, but I\'m interested in any solution even if it\'s in another language.

24条回答
  •  北海茫月
    2020-11-22 10:03

    In pseudo code:

    sql "select id from table"
    store result in list
    n = random(size of list)
    sql "select * from table where id=" + list[n]
    

    This assumes that id is a unique (primary) key.

提交回复
热议问题