Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Random rows

Author  Topic 

Alaveh
Starting Member

24 Posts

Posted - 2012-05-08 : 17:23:23
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

38200 Posts

Posted - 2012-05-08 : 17:26:43
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 - 2012-05-08 : 17:32:48
NICE

Thank you
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-05-08 : 17:33:06


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

Subscribe to my blog
Go to Top of Page
   

- Advertisement -