SQL Server 2008 - 如何加入 3 个表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5920383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 10:27:16  来源:igfitidea点击:

SQL Server 2008 - How to Join 3 tables

sqlsql-server-2008

提问by user450143

SQL Server 2008:

SQL Server 2008:

I have 3 tables

我有3张桌子

Users, Scores, Lessons

Users& Scoresare linked by StudentID

Users&ScoresStudentID

Scores& Lessonsare linked by LessonID

Scores&LessonsLessonID

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?

我知道如何加入两张桌子。我怎么扔到第三张桌子?

回答by Alex J

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

回答by Lokanathan

 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)