试着解释我的问题,抱歉我的英语不好:)
我忙于测验系统。
那些表格如下:
- Users
- Question
- Answers
- Sended Answers
我的问题并非真正需要用户表。
问题表就像:
- Questions.ID
- Question.Text (the question)
答案表就像:
- Answers.ID
- Answers.QuestionID
- Answers.Text
- Answers.Good
Sended Answers表就像:
- sAnswers.ID
- sAnswers.QuestionID
- sAnswers.FilledAnswers
- sAnswers.UserID
Answers.Good就像0 =不好/ 1 =好。
我得到所有带有UsersName的Sended Answers是什么,并查找sAnswers好不好。
我试过了:
public function countScores($bind=""){
$sql = "SELECT sAnswers.*, users.name, Answers.*
FROM sAnswers
INNER JOIN users ON sAnswers.userID = users.id
INNER JOIN Answers ON sAnswers.FilledAnswers = Answers.QuestionID";
$result = $this->run($sql,$bind);
return $result;
}
但结果不仅仅是sAwnsers的结果。 我做错了什么:-o
答案 0 :(得分:1)
我不确定你的架构设计是什么,但只是猜测,你对答案的加入应该是这样的Answers.ID
INNER JOIN users ON sAnswers.userID = users.id
INNER JOIN Answers ON sAnswers.FilledAnswers = Answers.ID";
你确定内部联接在你的情况下会起作用,即如果所有的表都被填满,那么尝试做左连接只是为了安全
LEFT JOIN users ON sAnswers.userID = users.id
LEFT JOIN Answers ON sAnswers.FilledAnswers = Answers.ID