4

Possible Duplicate:
How to get random record from MS Access database

In my project I have gone through a scenario, where i have to retrieve records from MS Access table RANDOMLY. What query should I use to retrieve the records in a random base??

Community
  • 1
  • 1
DS009
  • 169
  • 3
  • 5
  • 14

1 Answers1

5

Assuming that in a table MyTable you have a primary key ID field in a that is an autoincrement integer, you can do something like this to retrieve, say 10 random records from MyTable:

SELECT Top 10 *
FROM   (SELECT *,
           Rnd(ID) AS RandomValue
        FROM   MyTable)
ORDER  BY RandomValue 

Edit:
Found another similar answer: How to get random record from MS Access database

Community
  • 1
  • 1
Renaud Bompuis
  • 16,596
  • 4
  • 56
  • 86