Following are the methods i have already tried for picking random questions in Sql:
select top 10 id from testTable order by newid()
- It is unoptimised for large data
select top 10 id from testTable table sample(1 percent)
– But with table sample we cannot be sure that it will always return data as it works on probability of picking pagesI have tried several other ways as taking the mod of row numbers but i still want more optimised solution
I want only those ids which are not picked earlier.
I don’t want to use not in as sql doesn’t cache not in query.
Any approach which is more optimised than using not in query for picking ids already not picked is welcomed.
I will discuss schema of tables:
suppose there are following tables:
- table which is holding questions ,QuestionsTable
- table holding all users for test say testUserTale
- table containing questions for each user in test.
So i have to make sure student who has attempted question once should not see again in next test
RANDOM Procedure
This procedure generates a random number (but see Usage Notes).
Syntax
DBMS_RANDOM.RANDOM
RETURN binary_integer;
Pragmas
PRAGMA restrict_references (random, WNDS)
Return Values