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.
| Author |
Topic |
|
subhaoviya
Posting Yak Master
135 Posts |
Posted - 2012-09-10 : 09:19:33
|
| Hi, I have one query which returns me 100 records in result set. is it possible to select only 5 randomly from that resultset.ThanksSubha |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-09-10 : 09:23:04
|
select top (5) * from(here comes your select)dtorder by NEWID() Too old to Rock'n'Roll too young to die. |
 |
|
|
subhaoviya
Posting Yak Master
135 Posts |
Posted - 2012-09-10 : 09:28:33
|
| i need random selection, not top count.by using tamplesample we collect based on percentage, but for exact count random collection? |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-09-10 : 09:29:42
|
order by newid() will give random top 5 from your select/result Too old to Rock'n'Roll too young to die. |
 |
|
|
subhaoviya
Posting Yak Master
135 Posts |
Posted - 2012-09-10 : 09:39:02
|
| fine thanks a lot webfred. |
 |
|
|
|
|
|