MS Sql Random select

MS Sql Random select

 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 ?


MS SQL server shutdownC# Generate Random NumberHow to get Jquery selected optionAspnet Listbox Selectedindexchanged problems and solutiongodaddy hosting MS SQL server configurationJquery Dropdown Selected Valuelistbox to listboxms sql newid functionThis page contains secure and none secure information Do you want to display the none secure itemsDo you want to display nonsecure itemsMS SQL server Transaction commit rollbackms sql version


My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.

I'm Satalaj.