making a random selection

G

Gary Walter

Hi Daniel,

Selecting a random number of records
typically involves ordering those records
randomly, then selecting the TOP "n" records
after this random sort.


Here are some good examples given previously
by Jon, Michel, and John Viescas on this newsgroup
where they are selecting 5 random records:

SELECT TOP 5 Customers.*
FROM Customers
ORDER BY Rnd(1 + Len([CompanyName] & ""));

or if you have an AutoNumber as a Primary Key:

SELECT TOP 5 Categories.*
FROM Categories
ORDER BY Rnd([CategoryID]);

SELECT TOP 5 tblZips.Zipcode, tblZips.City, tblZips.State,
Rnd(Asc(Left([city],1))) AS RandNum
FROM tblZips
ORDER BY Rnd(Asc(Left([city],1)));

Please respond back if I have misunderstood.

Good luck,

Gary Walter
 
Top