I have 3 tables. Quizzes, Questions and Answers. Columns I want to use are;
Quizzes > id
Questions > quizid (blongs quiz)
Answers > userid, questionid (belongs question)
So my Answers table has no QuizID column. What I want is; group answers table by user ID depending on Question ID that belongs to specified Quiz ID.
In short; I want users that solved the Quiz. But I'm in a dead end :/
My query is like that;
Answer::join('questions', 'questions.id', '=', 'answers.id')
->join('quizzes', 'questions.quiz_id', 'quizzes.id')
->join('users', 'users.id', 'answers.userid')
->where('questions.quiz_id', $id)
->select('users.*')
->groupBy('questions.quiz_id')
->get()
My mistake is at the groupBy line. I don't want to group questions. I want to group answers that belongs to Quiz's questions. But I don't know how to do that.