SQL SERVER randomly sort query results

To randomly ordered or random X returns records, may be achieved by using the RAND function in the SELECT statement. But the RAND function generator only once in the query, so that each row will get the same value. The method may be achieved by using NEWID function in the ORDER BY clause to sort the result code is as follows:

  the SELECT *
  the FROM Northwind.Orders 
  ORDER BY NEWID () 

  the SELECT the TOP 10 * 
  the FROM Northwind.Orders 
  ORDER BY NEWID ()

Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2007/06/09/777378.html

Guess you like

Origin blog.csdn.net/weixin_33862188/article/details/93495937