Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Select statement with random order by

Posted on 2011-10-24
3
Medium Priority
?
184 Views
Last Modified: 2012-05-12
I have a select statement

I want to do an order by with a random sort on the rownumber returned.
0
Comment
Question by:lrbrister
  • 2
3 Comments
 
LVL 61

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 37020996
For SQL Server, you have the RAND() or NEWID() functions that can be used to generate random ordering.

e.g., ORDER BY NEWID()
0
 
LVL 61

Expert Comment

by:Kevin Cross
ID: 37021006
Some folks even combine the two like so to get more truly random sequence by seeding RAND().

ORDER BY RAND(CHECKSUM(NEWID()))

References:
http://msdn.microsoft.com/en-us/library/ms177610.aspx
http://msdn.microsoft.com/en-us/library/ms189788.aspx
http://msdn.microsoft.com/en-us/library/ms190348.aspx
0
 

Author Closing Comment

by:lrbrister
ID: 37023817
Perfect.  Thanks
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question