ASp.Net day

Micro blog



About Satalaj

www.satalaj.com

The best inline translator

Live lookup to see what asp.net developers are searching





MS Sql Random select       by Satalaj 3. July 2009 10:09
    

 If you want to select Random top 10 rows from MS sql table then use NEWID() function in order by clause .

For e.g. 
 
  

  select top 10 * from xyzTable order by NewID()


This statement will give always random top 10 rows from data table.

This is very helpful for getting lucky draw winners from data base.

select  top 3 from WinnersTable 
                          where CreateDate > '01-jan-2010' 
                          Order By newID()

*Note: it's performance is slow if table size is high.
Any other alternative or trick guys ?

     

Comments

Add comment


 

biuquotecode
Loading