It is said that this statement works: select top 5 * from tablename order by newid ()
I put it in the SQL query analyzer to execute it. It really works. I randomly extract 5 pieces of information and keep changing it. As a result, I don't need to use them when I use them in the program. They are always those pieces, so I made a research on this thing to find another method:
Newid () can generate data results such as "49869293-8891-4B31-B88E-A584D9621490", and each row produces different results. In this case, we can add such a column to the result set during the query, for example:
Select *, newsid () from Table Name
Then we are sorting this result set, because each newid () produces different values, so if it is sorted, of course it is also different, in this way, we can randomly select a few pieces of data. Then we add a top statement from the front to become:
Copy codeThe Code is as follows:
Select top 10 *, NewID () as random from table name order by random
You can use this method. We want the result. If you don't believe it, you can try it.