Search This Blog

Monday, July 21, 2014

SQL to Select a random row from a database table.

There are many ways to select a random record or row from a database table. We have SQL syntax for this task, we can easily fetch random row from sql database table.

     Table: builder

id
buildername
1
DLF
2
Amerpali
3
vision
4
rampark

SELECT TOP 2 *
FROM builder TABLESAMPLE (100 ROWS) order by NEWID()

OUTPUT:

id
buildername
2
Amerpali
4
rampark

No comments :