1

我有四张桌子

student
-------
id, int
firstName, varchar
lastName, varchar

course
------
id, int
name, varchar

semester
--------
id, int
name, varchar

mark
----
studentId, int
courseId, int
semesterId, int
mark, int

我想做一个 sql 查询来检索表firstNamelastName的每一行。courseNamesemesterNamemarkmark

我试图用 INNER JOIN 来做,但我不能为不止一张桌子做 INNER JOIN。

我终于达到的那个代码

select student.firstName, student.lastName, course.name, semester.name, mark.mark
from mark
INNER JOIN student ON student.id = mark.studentId
INNER JOIN course ON course.id = mark.courseId
INNER JOIN semester ON semester.id = mark.semesterId
4

2 回答 2

1

尝试 theta 风格加入:

select student.firstName, student.lastName, course.name, semester.name, mark.mark
from mark, student ,course, semester
WHERE  student.id = mark.studentId AND course.id = mark.courseId AND semester.id = mark.semesterId
于 2012-05-16T12:02:44.333 回答
1

在 Ms Access 中,您必须在具有多个连接的查询中包含括号:

select st.firstName, st.lastName, c.name, sm.name, m.mark
from (((mark m
        INNER JOIN student st ON st.id = m.studentId)
        INNER JOIN course c ON c.id = m.courseId)
        INNER JOIN semester sm ON sm.id = m.semesterId)
于 2012-05-16T11:59:55.043 回答