INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Other

Retrieving random selection of records by AWithers
Posted: 2 Oct 02

This FAQ outlines a way of retrieving a random set of records for audit or other prurposes.

The method requires that the table has a numerical field on which to operate

the sql is very simple

select top X from yourtable
order by rnd(numericalfield)

This will give the x records and will be different everytime it is run.

If you need to ensure that you don't get any of the records from last time it was run then the keyfield(s)  of the records could additionally be placed in a temporary table (e.g. tblauditedlasttime)and excluded from the search

e.g.

select top X from yourtable
order by rnd(numericalfield)
where keyfield not in (select keyfield from tblauditedlasttime)

I hope this is useful to someone

Andy

Back to Microsoft: Access Queries and JET SQL FAQ Index
Back to Microsoft: Access Queries and JET SQL Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close