SQL Server 2008:
SQL Server 2008:
I have 3 tables
我有3张桌子
Users, Scores, Lessons
Users
& Scores
are linked by StudentID
用户和分数由StudentID链接
Scores
& Lessons
are linked by LessonID
分数和课程由LessonID链接
I want to display the scores for a StudentID
. Here are the columns I want to display
我想显示StudentID的分数。这是我想要显示的列
Users.Name, Scores.LessonID, Scores.Result, Lessons.Title
I know how to Join the 2 tables. How do I throw in the 3rd table?
我知道如何加入2个表格。我如何投入第3桌?
2 个解决方案
#1
17
Same way as one table:
与一个表相同:
SELECT Users.Name, Scores.LessonID, Scores.Result, Lessons.Title
FROM Users
INNER JOIN Scores ON Users.StudentID = Scores.StudentID
INNER JOIN Lessons On Scores.LessonID = Lessons.LessonID
#2
0
SELECT *
FROM T1
INNER JOIN T2
ON T2.C = T1.C
INNER JOIN T3
LEFT JOIN T4
ON T4.C = T3.C
ON T3.C = T2.C
is equivalent to (T1 Inner Join T2) Inner Join (T3 Left Join T4)
#1
17
Same way as one table:
与一个表相同:
SELECT Users.Name, Scores.LessonID, Scores.Result, Lessons.Title
FROM Users
INNER JOIN Scores ON Users.StudentID = Scores.StudentID
INNER JOIN Lessons On Scores.LessonID = Lessons.LessonID
#2
0
SELECT *
FROM T1
INNER JOIN T2
ON T2.C = T1.C
INNER JOIN T3
LEFT JOIN T4
ON T4.C = T3.C
ON T3.C = T2.C
is equivalent to (T1 Inner Join T2) Inner Join (T3 Left Join T4)