我正在尝试使用以下查询加入四个表,我收到上述错误
SELECT student.names, student.surname,
coursemarks.mark,
class.form,class.id
FROM `student`, `course`
INNER JOIN `course` on course.courseid = coursemarks.course.id
INNER JOIN `coursemarks` on student.idNumber = coursemarks.studentid
INNER JOIN `class`on student.idNumber = class.studentID;
这是我的数据库架构就像我有一个带有主键idNumber的学生表。通过引用student.idNumber键将课程标记链接到学生。通过在课程字段中引用courseID键,coursemarks表链接到课程表。类表还引用了student.idNumber键。我该如何解决这个问题
答案 0 :(得分:1)
您的查询中有拼写错误。您尝试多次使用课程表,如下所示,另一个在您加入时。从下面的行中移除course
:
FROM `student`, `course`
所以它看起来像
FROM `student`
同时更改连接语句的顺序(一个包含课程和课程标记),如下所示
SELECT student.names, student.surname,
coursemarks.mark,
class.form,class.id
FROM `student`
INNER JOIN `coursemarks` on student.idNumber = coursemarks.studentid
INNER JOIN `course` on course.courseid = coursemarks.courseid
INNER JOIN `class`on student.idNumber = class.studentID;
答案 1 :(得分:0)
SELECT s.names
, s.surname
, m.mark
, l.form
, l.id
FROM student s
JOIN coursemarks m
ON m.studentid = s.idNumber
JOIN course c
ON c.courseid = m.course.id
JOIN class l
ON s.idNumber = l.studentID;