在sqlServer上我有2个表:
table1: Students => studentName=david, class1Id=2,class2Id=4
table2: classes=> classId=2, className="class1"
classId=4, className="class2"
class1Id
和class2Id
与classes.classId
我想做sql查询得到:
studentName=david, className1="class1",className2="class2",
我知道在两张桌子之间加入,但不是那样
谢谢!
答案 0 :(得分:0)
您只需要JOIN
到Classes
两次:
Select S.StudentName,
C1.ClassName As ClassName1,
C2.ClassName As ClassName2
From Students S
Join Classes C1 On C1.ClassId = S.Class1Id
Join Classes C2 On C2.ClassId = S.Class2Id