Thursday, August 14, 2008

Randomize Query in SQL

Sometimes you want to return a bunch of data from a table, but you want it coming back in a random order. Maybe it's for keeping some content on a home page fresh. Here's how:

ssql="SELECT TOP 10 * FROM [someTable] ORDER BY NEWID()"


The key here is "ORDER BY NEWID()"

No comments: