SQL Random Rows

Found a super slick way to select random rows from MS SQL 2000. I'm just going to quote is here for posterity.

The old method was to grab the primary keys of all the records, then putting them into an array, count the array and pick a random number using the system random function. This random number is the array index, so then you can pull the primary key from the array and use it to retrieve the random record.

In other words, a pain in the ass.

I just found out, thanks to SQL Team, that you can do this: SELECT TOP X whatever FROM sometable ORDER BY newid()

As stupid as it seems, the damn thing works! X is the number of records that you want. newid() returns a GUID. When the query runs, a column with GUIDs is created and the results are sorted before the X records are retrieved.

Works like a charm.