sql语句查询数据是和三张表有关联的应该怎么写?
比如说:有三张表School,Class,Student三张表各自的字段分别如下,School:SchoolId,ClassId;Class:ClassId,Studen...
比如说:
有三张表School,Class,Student
三张表各自的字段分别如下,
School:SchoolId,ClassId;
Class:ClassId,StudentId;
Student:StudentId,StudentName;
然后我希望经过SELECT查询得到SchoolID和StudentName两个字段
而其中表Student和表Class的StudentId要对应,以及表Class和表School的ClassId也要对应..
也就是说条件是:Student.StudentId = Class.Student
Class.ClassId = School.ClassId
请问这个应该怎么写? 展开
有三张表School,Class,Student
三张表各自的字段分别如下,
School:SchoolId,ClassId;
Class:ClassId,StudentId;
Student:StudentId,StudentName;
然后我希望经过SELECT查询得到SchoolID和StudentName两个字段
而其中表Student和表Class的StudentId要对应,以及表Class和表School的ClassId也要对应..
也就是说条件是:Student.StudentId = Class.Student
Class.ClassId = School.ClassId
请问这个应该怎么写? 展开
4个回答
展开全部
select School.SchoolID,Student.StudentNamefrom Student left join Class on Student.StudentId = Class.Student left join School on Class.ClassId = School.ClassId
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select schoolID,StudentName from school join class on school.classid=class.classid join student on class.studentid=student.studentid
或者
select schoolID,StudentName from school,class,student where school.classid=class.classid and class.studentid=student.studentid
或者
select schoolID,StudentName from school,class,student where school.classid=class.classid and class.studentid=student.studentid
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SELECT SCHOOLID,STUDENTNAME FROM SCHOOL,CLASS,STUDENT
WHERE SCHOOL.CLASSID=CLASS.CLASSID AND CLASS.STUDENTID=STUDENT.STUDENTID
WHERE SCHOOL.CLASSID=CLASS.CLASSID AND CLASS.STUDENTID=STUDENT.STUDENTID
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询