articles:

select random records from access

Here is a very simple way of selecting random records from an Access database:

SELECT TOP 5 * FROM [tableName] ORDER BY rnd(INT(NOW*id)-NOW*id)

The only prerequisite is that you have an AutoNumber Id column. It should also be noted that although this generates a random set of records, they are not truely random in a mathematical sense, but should be sufficiently random for most uses.

This method of selecting records also works in sql server, but you have to change rnd to rand.

Comments

Posted on 16 February 2011 04:31:00 GMT by panxo
this is the only code that worked for me... the others codes i had found were giving me random rows, but every time i ran the query the same rows appeared...

now with this code every time i run the query gives me a different set of rows!!

thank you very much!!!
Posted on 24 April 2011 15:14:00 GMT by anonymous
many thanks. works like a charm.
Posted on 08 July 2011 11:48:00 GMT by Nidhin.K.V
Thanku frrnd..
its wrkng
Posted on 01 August 2011 20:13:00 GMT by Bob
Worked without a hitch! Thank you!
Posted on 09 September 2011 12:39:00 GMT by professionalsna
Thanks it Works for me
Posted on 03 February 2012 12:11:00 GMT by Eduardo Simoes
Cool,tnx for share

Post a comment

name:
(optional)

email:
(optional)

comment:

call us on 01344 762988