有三个表,其中single表存放了单选题的信息,examquestions表存放了某个试卷各个部分的试题组成,这里仅关注单选题型,
answer 表存放的是考生的答题信息,即考生如果做了试卷的某些题目,则把这些题目及答题内容插入到answer表。各个表主要的字段如下。
kaoshi_single表: singleid, ssubject, Sanswer
kaoshi_examquestions表:  examquestionid,questionid,questiontype,examid
kaoshi_answer表:answerid,xuehao,examid,answer,questionid,questiontype
现在我想查询某个学生的考试答案以及原始题目及正确答案,sql为select  * from kaoshi_single s join kaoshi_examquestions e join kaoshi_answer a where a.questionid = e.questionid and a.questiontype='single' and s.singleid=e.questionid and e.questiontype='single' and e.examid='"+examid+"' and a.xuehao='"+xuehao+"'";其中最后一行的加号前后的examid和xuehao为变量。那么这个语句有个问题,即学生如果做试题时某题目没有做(留空),那么这个题目的答题信息就没有插入answer表,因此通过上述sql语句查看答案时该题目并不会显示出来。现在我想把某个试卷的单选题的信息及学生的答题信息都查出来,即使学生没做,也要列出题目,只是学生答案显示为空。 按照我的分析应该是要用左外连接,但我用下面左外连接也没用。
sql="select  * from kaoshi_single s left join kaoshi_examquestions e on s.singleid=e.questionid  left join kaoshi_answer a on a.questionid = e.questionid  where   a.questiontype='single' and  e.questiontype='single' and e.examid='"+examid+"' and a.xuehao='"+xuehao+"'";
请教一下高手要怎样写,最好还能简要的解释一下。谢谢。