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 ...
AddThis

Related discussion

Related podcasts

Events coming up

  • Nov 19

    SQLBits V

    Newport, United Kingdom

    SQLBits is Europe's largest SQL Server conference, and SQLBits V will be the biggest and best yet. On November 19th we are holding a day of pre-conference seminars; on November 20th we have a pay-to-attend day of SQL Server 2008 and R2 content; and on Saturday November 21st we have our usual free community conference.

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