I have a question table outlined as follows.
id | question | answer | program | difficulty
I want to create an SQL statement that selectively selects 5 questions for each of the individual programs when the difficulty is simple.
So, if there are 4 programs, I will have 20 questions.
I thought something like this ...
SELECT * FROM questions WHERE difficulty='easy' AND syllabus IN ( SELECT DISTINCT syllabus FROM questions WHERE difficulty='easy' ) LIMIT (5* ( SELECT COUNT(DISTINCT syllabus) FROM questions WHERE difficulty='easy' )
But this does not return 5 from each individual line, only the correct number of questions from any curriculum.
source share