---
title: "random questions from sql server"  
description: "random questions from sql server"  
author: "Anonymous User"  
published: 2013-05-07  
updated: 2013-05-07  
canonical: https://www.mindstick.com/forum/826/random-questions-from-sql-server  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 1 minute  

---

# random questions from sql server

Hi! Everyone!\
I am working on a survey application. I have a sql [server database](https://www.mindstick.com/forum/156824/what-is-normalization-in-sql-server-database) holding upto 3000 [survey questions](https://answers.mindstick.com/qa/108400/can-you-ask-survey-questions-on-quora). I call database for a set of 10 questions. I have to make sure \
that none of the of the questions are repeated for the longest time possible. What is the best possible [approach](https://www.mindstick.com/interview/985/what-are-the-approaches-that-you-will-follow-for-making-a-program-very-efficient) I can take here? Write a [custom](https://www.mindstick.com/blog/12298/use-custom-writing-services-to-get-through-the-finals) randomization \
[algorithm](https://www.mindstick.com/blog/119/implementing-cryptography-in-c-sharp-dot-net-by-using-sha1-algorithm) or [SQL server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server) provides some functionality.\
Please help me!\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Loos!\
SELECT question_idFROM [questions](https://www.mindstick.com/blog/124895/hp-hpe0-s54-cheat-sheet-exam-questions-bank-for-guaranteed-success) ORDER BY NEWID()gives you all the question ids in random order. store the list, and work your way down.\
There isn't a way to ensure the longest time between repeats without storing the order. You could make it another column on the same table...\
EDIT: a variation on Mr Jacques' idea:\
how about a column named random? Shuffle the order like so:\
update questions set random = ( SELECT question_id FROM questions ORDER BY NEWID())then get each new question like this:\
select * where random = 'prev_question_id';Then you could shuffle the order at intervals, every night maybe.


---

Original Source: https://www.mindstick.com/forum/826/random-questions-from-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
