How do I select a certain number of records randomly from a table?

A

AdamW3995

I'm building a database to give a randomized test based off of the number of
questions I select. Example: I have a table with 100 questions, but I want
to only select 20, at random, and have them displayed in a report. Can this
be done easily? I already know how to randomize the questions, I just need a
way to tell it to select only a designated amount.
 
A

AdamW3995

Is that supposed to be an expression? The idea is to give a field on the
startup form, and based on the number indicated in that field, it would pull
that number of questions. I need to limit access to the table entirely.
 
D

Dale Fye

No, it is supposed to be a SQL statement, although I forgot to put the field
names in the statement. It should read:

SELECT Top 20 Question_Num, Question_Text, Question_Response_Type, Field2,
Field2, Field3, Field4
FROM yourTable
ORDER BY (put something in here to order the values by)

You don't indicate where you want to display these questions when you are
done pulling them. I assume you have a form to display the question and the
potential responses. You just indicated you wanted to know how to select a
specific number of questions. The down side of using the TOP predicate is
that it will pull the top 20 (in this case) plus any additional records that
have the same values in the fields used in the order by criteria contained
in the 20th record. If you have a database of addresses, and sort by
ZipCode, you could get a 100 or more records. If, on the other hand, you
have a field in the table that contains a random double precision number,
sorting on this field will generally get you almost unique results.

Dale
 
Top