Search This Blog & Web

Thursday, July 23, 2009

Returning random result from a dataset

Problem: Many of the developers write complex and huge code to return random images or news on every page refresh on its website or project.

Solution: Sql server provides easy way to return random result on each call.


Select * from [table1] order by newid()

if you have 2 records in your table you will get different result each time.

1 comment:

Maria said...

this is a great and simple way to get unique result each time...