我想通过内部联接从更多表中选择数据。
这些是我的桌子。
Student (studentId, firstName, lastname) Exam (examId, name, date) Grade (gradeId, fk_studentId, fk_examId, grade)
我想写一份声明,显示学生去过哪个考试,年级和日期。日期后排序。
这是我的声明。它可以运行,但是我想确保自己做的正确。
SELECT student.firstname, student.lastname, exam.name, exam.date, grade.grade FROM grade INNER JOIN student ON student.studentId = grade.gradeId INNER JOIN exam ON exam.examId = grade.gradeId ORDER BY exam.date
几乎正确..查看联接,您引用的字段错误
SELECT student.firstname, student.lastname, exam.name, exam.date, grade.grade FROM grade INNER JOIN student ON student.studentId = grade.fk_studentId INNER JOIN exam ON exam.examId = grade.fk_examId ORDER BY exam.date