I am developing a system which selects questions from a database to generate a test/exam.
Each question has a set 'question type' ('q_type'). I have a database of questions and need to select 4 questions, each with a different 'q_type'.
The basic query to select 4 random questions at the moment is:
SELECT * FROM questions ORDER BY RAND() LIMIT 0,4
This obviously does not take into account the fact that each question should have a different 'q_type'.
I would like to be able to do something that follows this logic (i need something to fill in the square brackets):
SELECT * FROM questions WHERE ['q_type' is DISTINCT] ORDER BY RAND() LIMIT 0,4
I have tried using GROUP BY 'q_type', but that simply gives the first question for each 'q_type', not a different question of that type each time.
Any help would be great, as I am completely stumped at the moment (I am working with a overblown PHP loop which simply queries the DB 4 times, with an updated WHERE 'q_type'!=XX each time).
Thanks for any help!