How to request a random row in SQL?

前端 未结 29 2948
孤城傲影
孤城傲影 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:21

    In MSSQL (tested on 11.0.5569) using

    SELECT TOP 100 * FROM employee ORDER BY CRYPT_GEN_RANDOM(10)
    

    is significantly faster than

    SELECT TOP 100 * FROM employee ORDER BY NEWID()
    

提交回复
热议问题