MyTechnoBook - Query To Select A Random Record From A Table in A SQL Server Database
MyTechnoBook - Query To Select A Random Record From A Table in A SQL Server Database
com
There is a function in SQL Server RAND() which generates Random Numbers. This
function does not work as expected while selecting a RANDOM row from a table in SQL
Server.
To address this issue, there is a workaround to select a RANDOM row from a table in SQL
Server. Here you go…
Now insert some sample data into the Temp Table using the following query:
Now run the following queries to see how 2 RANDOM rows a selected from Temp Table
every time you run these queries.
Here is the output of the above queries. Run these queries a couple times to see the
difference in the number of selected rows every time the above queries are run.