Fetch random data from SQL Server 2005

Generally when we fetch data from sql server is in same order. or We can fetch data in ascending or descending order. But to fetch data randomly for each time use this query.

Suppose there is a table Que where all the questions are stored and another table QChoice which store the Choices for each question

Structure of QChoice is like that:

Ch_id int identity(1,1),
Qid int,
Choice


Qid is quitionid which is fetched from Que table

now to show Choices randomly for each question use the query:

Select * from QChoice where qid='1' order by newid()

NewID() is the function used for generating randomly result.

Ebook Download
View all
SQL Jobs
Read by 0 people
Download Now!
Learn
View all