How to request a random row in SQL?

前端 未结 29 2918
孤城傲影
孤城傲影 2020-11-21 06:45

How can I request a random row (or as close to truly random as is possible) in pure SQL?

29条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-21 07:32

    ORDER BY NEWID()
    

    takes 7.4 milliseconds

    WHERE num_value >= RAND() * (SELECT MAX(num_value) FROM table)
    

    takes 0.0065 milliseconds!

    I will definitely go with latter method.

提交回复
热议问题