If you have indexes on the exam and question of the table, the database should use that to fetch back just the answers to that question of that exam (the rest of the table won't be looked at), and will then join it very efficiently. This is virtually instantaneous.select count(*) from answer_table a_1, answer_table a_2 where a_1.student_id = a_2.student_id and a_1.exam_id = ? and a_1.question_id = ? and a_1.answer = ? and a_2.exam_id = ? and a_2.question_id = ? and a_2.answer = ?
If you don't have any indexes, then you will probably wind up scanning the full table twice. Which is not good, but if you are using it for bulk access, it is not horrible either...
In short, live by the saying, The key, the whole key, and nothing but the key. So help me Codd. (Until you actually observe, not theorize, the existence of performance problems.)
In reply to Re: Re^3: SQL database architecture
by tilly
in thread SQL database architecture
by punchcard_don
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |