I have a quiz system which questions have multiple choises.
I want to show the right answer plus four more wrong choices. Totally I must have five choices.
SELECT *
FROM `choises`
WHERE questionid = :qid
ORDER BY correct DESC, RAND()
LIMIT 5
Assuming correct
is some sort of int. Otherwise you might need to change DESC
to ASC
.
You can 'shuffle' the 5 results using one more ORDER BY RAND()
like this:
SELECT * FROM (
SELECT *
FROM `choises`
WHERE questionid = :qid
ORDER BY correct DESC, RAND()
LIMIT 5
) as t
ORDER BY RAND()