Select the top records randomly in sql server


we need to select the top records randomly to show in the front page.

for example, you can see in the facebook. It will show the 5 of friends in the list. 

If you refresh the page it will show another set of users.

In order to get the top 5 records randomly we need to use the following query

 SELECT TOP 3 * FROM Products ORDER BY NEWID()

The output will be like the following.

Rand1.jpg


When you execute again then you will get the another set of different records for the same query.

Rand2.jpg


Next Recommended Reading Get top 10 records from dataset