Comparing fields

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have a table that is compiled with test data (student responses on a
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 wrote:
Quoted text here. Click to load it

I'd let SQL do it.  Try a newsgroup pertinent to your database (i.e. for
MySQL, comp.databases.mysql).

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Comparing fields

Quoted text here. Click to load it

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

Site Timeline