|
Developer's Guide to ASP.NET 3.5 |
|
Master ASP.NET 3.5 development using C# and Visual Studio.NET 2008. Web forms, server controls, data binding, AJAX, ASMX and WCF services and more... |
|
|
Beat stress - learn Kriya Yoga Meditations |
|
A six week online course in our style of Kriya Yoga is available absolutely FREE. Very few websites teach you the ancient art and science of Kriya Yoga in such a systematic and authentic manner. |
|
Fetching Random Rows From SQL Se
Tip: Fetching Random Rows From SQL Server
Recently I needed to fetch random rows from a SQL server table. If you have
an integer column then using RAND() function goes well. However in my case there
was no number column. In such cases you can use the following query:
SELECT TOP <n> <column list>
FROM <table>
WHERE <criteria>
ORDER BY NEWID()
The key is the use of NEWID() function that returns a GUID. An example query
would look something like this:
SELECT TOP 10 *
FROM Employees
ORDER BY NEWID()
This way is also useful for selecting data for testing purposes.