Library code snippets

Randomly Sorting Records

Ever needed to grab a selection of random rows from a table? Well, it's surprisingly easy in SQL Server 2000, using the NEWID() method. The code below selects 10 random rows from "myTable".

SELECT TOP 10 id,title FROM myTable ORDER BY NEWID()

Great!

Comments

  1. 28 Apr 2006 at 07:05
    Hi iam Ram fro Hyderabad doing MCA ,Urs functin is very nice ,iam going to develop a pos software ,i need ur help on Database and query desinging. thank Q
  2. 01 Jan 1999 at 00:00

    This thread is for discussions of Randomly Sorting Records.

Leave a comment

Sign in or Join us (it's free).

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...

Want to stay in touch with what's going on? Follow us on twitter!