How to request a random row in SQL?

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

    I don't know how efficient this is, but I've used it before:

    SELECT TOP 1 * FROM MyTable ORDER BY newid()
    

    Because GUIDs are pretty random, the ordering means you get a random row.

提交回复
热议问题