Q. How do I get a random sort result?
A. To get a randomly sorted column, or to return a randomly selected column of x, you can use a random number. However, the RAND function can only return one result in a query. You can do an order by on the column returned by the NOWID function. Take a look at the example:
SELECT *
From Northwind. Orders
ORDER by NEWID ()
SELECT TOP 10 *
From Northwind. Orders
ORDER by NEWID ()
This passage is really laborious, regardless of the original text, the direct translation.
However, it is important to note that this method is to scan the entire table, and then produce a computed column reorder, it is best not to do such a large table, otherwise it will be very slow.
Q. How can I randomly sort query results?
A. To randomly order rows, or to return x number of randomly chosen rows, you can use the RAND function inside the SELECT Statement. But the RAND function was resolved only once for the entire query, so every row would get same value. You can use a ORDER by clause to sort the rows by the result from the NEWID function, as the following code shows:
SELECT *
From Northwind. Orders
ORDER by NEWID ()
SELECT TOP 10 *
From Northwind. Orders
ORDER by NEWID ()
-sql Server MVPs
http://www.bkjia.com/PHPjc/631149.html www.bkjia.com true http://www.bkjia.com/PHPjc/631149.html techarticle Q. How do I get a random sort result? A. To get a randomly sorted column, or to return a randomly selected column of x, you can use a random number. But the RAND function can only return one in a query ...