SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Random rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Alaveh
Starting Member

24 Posts

Posted - 05/08/2012 :  17:23:23  Show Profile  Reply with Quote
How can i select random rows in sqlserver queries ?

for example the below query has near by 3000 rows answer :
select F1 from Tbl1

AND the below query has 100 rows but are fixed in all runs :
select TOP 100 F1 from Tbl1

How can i select randomize 100 rows ?

tkizer
Almighty SQL Goddess

USA
35007 Posts

Posted - 05/08/2012 :  17:26:43  Show Profile  Visit tkizer's Homepage  Reply with Quote
select TOP 100 F1 from Tbl1
order by newid()

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Alaveh
Starting Member

24 Posts

Posted - 05/08/2012 :  17:32:48  Show Profile  Reply with Quote
NICE

Thank you
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
35007 Posts

Posted - 05/08/2012 :  17:33:06  Show Profile  Visit tkizer's Homepage  Reply with Quote


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000