I am trying to figure out how to go about with this scenario in mySQL -
There are three tables - t_student, t_teacher, t_result
structure of the tables (basically columns in each of them) are as below:
t_student:
s_id, s_name, s1, s2, s3
where s_id is the primary key, s_name is student name, (s1,s2,s3) are subjects like math, phy, chem etc..
t_teacher:
t_id, t_name, s1, s2, s3
where t_id is the primary key, t_name is teacher name, (s1,s2,s3) are subjects like math, phy, chem etc..
t_result:
r_id, s_name, t_name, count
where r_id is the primary key, s_name is the student name (from student table), t_name is the teacher name (from teacher table) and count gives count (more on that in a moment)
Now, what I would like to do is as below:
there could be any number of records in student and teacher table, and none as of now in the results table. Now, using mySQL I would like to scan the contents of student table, and for each record in this table, i would like to pickup:
s1 and then compare the value with (s1,s2,s3) columns in teacher table s2 and then compare the value with (s1,s2,s3) columns in teacher table s3 and then compare the value with (s1,s2,s3) columns in teacher table
and the get the number of matching values and store in count.
For more clarity, if for the first record in student table, s1, s2 and s3 are "phy", "chem" and "maths", and if the first record in teacher table is "maths", "phy", "computer", then in this case, student.s1 matches with teacher.s2 - so now count is 1. then student.s2 is matched against the s1,s2,s3 in teacher table, but match is 0, so count is kept 1; again student.s3 is matched against s1,s2,s3 in teacher table,this time it matches with teacher.s1, so count is incremented to 2. So at the end of comparison of first record in student table with first record of teacher table, i get the count=2. Now i would insert a row into the result table, with student name, teacher name, and the so obtained count.
Basically I want to get the number of s1,s2,s3 match between the student table and teacher table, for each row in student table and then put this into the result table.
I know only basic operations in mysql- like selecting inserting deleting etc.. I am assuming that such an operation would require more than that, something like plsql and stored procedure?
FYI, I am using phpmyadmin, and the tables are stored there. I would be using php to fetch the results from the table,and to execute these queries.
Please let me know the approach for this.
Thank You!