How to select x random records

M

mistux

I need to select 200 random customers from my table, how can I do that?

Table: tblCustomers
PK: CustI
 
M

Michel Walsh

Hi,



SELECT TOP 200 *
FROM myTable
ORDER BY Rnd( NumericalFieldNameHere )



If an expression contains a field name, it is evaluated for each record, so
here, all the records get a random number which, once ordered, will supply
your 200 random records.

If an expression does not contain a field name, it is evaluated once:

SELECT Rnd(), *
FROM myTable


will return the same number (random) for each and every record.


SELECT Rnd(NumericalFieldNameHere), *
FROM myTable

will got a different random number, for each record.




Hoping it may help,
Vanderghast, Access MVP
 
Top