Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random selection

Status
Not open for further replies.

liamm

Technical User
Aug 12, 2002
102
GB
Hi, I have a table with a list of questions and answers. The questions and answers are split into different subjects.

ID, Subject, Question, Answer

I can generate a random number of questions using the code below:

SELECT TOP 25 ID, Question, Answer
FROM RefresherQuestions
ORDER BY RND(ID);

How can I choose to generate a random number of questions on a specific subject? i.e. Select 25 random questions and answers on Animals
Thanks

If you can help, GREAT
If I can help, EVEN BETTER
 
If subject is a string, something like...

SELECT TOP 25 ID, Question, Answer
FROM RefresherQuestions
WHERE Subject = 'Animals'
ORDER BY RND(ID);

If subject is a number, something like...

SELECT TOP 25 ID, Question, Answer
FROM RefresherQuestions
WHERE Subject = 2
ORDER BY RND(ID);

Hope this helps...

There are two ways to write error-free programs; only the third one works.
 
Thanks GHolden If you can help, GREAT
If I can help, EVEN BETTER
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top