我正在尝试开发学生信息系统。在此系统中,我想在学生的个人资料页面上显示学生的课程和讲师,并且我无法编写正确的内部加入查询。这些是我的桌子;
Students
id
name
last_name
major
faculty
classes
Instructors
ID
name
last_name
major
Classes
class_id
class_name
class_faculty
instructor // Here I have the instructor who teaches that class
student // Here I have the student who takes that class
最佳答案
jcaron是正确的:您需要一个附加表来代表已报名参加课程的学生。
Students
id
name
last_name
major
Instructors
ID
name
last_name
major
Classes
class_id
class_name
class_faculty
instructor_id
StudentRegistrations
student_id
class_id
然后,您可以执行以下操作:
SELECT * FROM StudentRegistrations reg
INNER JOIN Students ON Students.id = reg.student_id
INNER JOIN Classes ON Classes.class_id = reg.class_id
INNER JOIN Instructors ON Instructors.ID = Classes.instructor_id
关于mysql - MYSQL中的内部联接查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25336467/