I have one table with questions and another table with correct answer
If any user attempt question then I need result with marks.
I want result:-
Thanks in advance!
I have one table with questions and another table with correct answer
If any user attempt question then I need result with marks.
I want result:-
Thanks in advance!
What have you tried? You seem to have a set of related tables. How about writing out a plain language sentence or two on how you want your query to manipulate the various bits of data. I often find this helps to get my head around things.
I have tried following query
select
sum(questions.marks)
from
questions
inner join answers on questions.question_id = answers.question_id
inner join user_quiz_attempt on answers.answer_id = user_quiz_attempt.answer_id
where
answers.is_true = 1
and user_quiz_attempt.user_id = 12/13
Incorrect result
user_id marks_obtained
12 10
13 15
I don't have your data or tables, so I can only do something off the top of my head...
I think you need a GROUP BY xxtable_namexx.user_id
in order to sum properly. But you seem to allow multiple attempts, so how are you supposed to sum? Count all correct answers, regardless of previous incorrect attempts (I'm assuming this is how you want to do it)?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.