|
-
Sep 29th, 2010, 12:29 AM
#1
Thread Starter
Lively Member
[RESOLVED] Method to select statistically random rows from SQL server
Hi people, long time no speak.
I've been looking into a few methods to select a list of statistically random rows from a sql db from vb6 (and maybe vb2008 as well).
One that seems the most interesting is on these forums, posted by szlamany Link here:
http://www.vbforums.com/showthread.p...andom+rows+sql
Essentially:
A concept you can use for any database would be:
1) Determine the number of rows in the table - SELECT COUNT(*) will do that
2) Use RND() from the client side - with the number of row value - to determine which record you want
3) Do a query something like this to get that one record
Code:
Select Top 1 *
From (Select Top {TheRandomRowFoundinStep2} *
From SomeTable Order by PriKey Desc) "XYZ"
Another method I've seen, amongst many, is to use:
Code:
SELECT TOP 1 column FROM table
ORDER BY NEWID()
I havent yet really tried either method, but my question, I guess, is:
Is using Rnd() or NEWID() actually statistically random, or psuedo random?
I would prefer a method that is statistically random.
I suspect that szlamany's method may be the better way for me, but the second option may be easier to implement (for me at least!)
If neither of these methods are so, could anyone suggest a way to do it.
Essentially I just want to select 100 random records as statistical samples.
Thanks
josh
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|