sql - Mysql query different random conditions -
i need have random question question bank. have table, question, column: questiontype. need random questions table depending on request of user.
for example, chooses, questiontype: ['identification', 'multiple choice'] , number of questions per questiontype: ['10', '20'].
so need query random 10 questions column questiontype value identification , 20 random questions column questiontype value multiple choice.
i have sql statement:
select question question questiontype = 'identification' order rand() limit 10;
so how can add condition:
questiontype = 'multiple choice' order rand() limit 20
can please me? thanks!
try this:
select question ( (select question question questiontype = 'identification' order rand() limit 10) union (select question question questiontype = 'multiple choice' order rand() limit 20) ) t order rand()
see demo in sql fiddle.
Comments
Post a Comment