Friday, June 8, 2012

Selecting Random Rows in SQL Server


Here is the quick and easy way to select random rows in sql server.

SELECT <columns Name> FROM <table name> ORDER BY NewID()

Reference from : Brian Jeremy
......

Hope it will help you.

Thanks
Solomon S.


If information is helpfull then don't forget to post comments

3 comments:

Manmath Baral said...
This comment has been removed by the author.
Manmath Baral said...

I don't know whether this (function rand() OR random()) exists in SQL SEVER or not. But in MySQL there is a simple way to get random records from one table.

EXAMPLE
----------

SELECT *
FROM table_name
ORDER BY RAND()
LIMIT 10;

Solomon Sarkar said...

Hi Manmath Baral, Yes in MySQL it's RAND() and in MSSQL it is NewID() their is no function called RAND().