Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Comparing fields
March 19, 2009, 3:09 am
rate this thread
multiple choice test). In another table I have the answer keys to many
tests. I would like to take the test id and use this to find the
correct answer key and compare each student's responses to the answer
key. I also would like to create another table that will list a 1 if
the student answered the question correct and a 0 if they did not.
Any thoughts on how to compare two fields from two different
tables???? Thanks! (I'm a rookie at php).
Re: Comparing fields
Join two (or more) tables. Note that in this example, if there are
30 questions on the test, you've got 30 records in Answer_key_table
and 30 records per student in Student_test_table.
Let's suppose you have two tables:
Student_name (or ID)
Assuming you've got at most one test per student (or have another field
in the Student_test_table to distinguish them, you can get student
name and the score for the test:
SELECT Student_name, sum(if(Student_test_table.Student_answer =
FROM Student_test_table JOIN Answer_key_table
ON Student_test_table.Test_ID = Answer_key_table.Test_ID
AND Student_test_table.Question_number = Answer_key_table.Test_ID
GROUP BY Student_name
- » How to keep update one Mysql database with another MySQL database?
- — Next thread in » PHP Scripting Forum