Problem
How to get schedule for instructor from table CourseClass by SQL query?
如何通过SQL查询从表CourseClass获取讲师的时间表?
Course table has relation with Instructor table many to many and generated Instructor Course table.
课程表与讲师表有很多关系,并生成了讲师课程表。
Course table has relation with Class table many to many and generated CourseClass table. and my diagram as following:
课程表与Class表有很多关系,并生成了CourseClass表。和我的图表如下:
ERD数据库设计digram
what i try is
我尝试的是
SELECT dbo.Class.*, dbo.Course_Class.*, dbo.Course.*, dbo.Inst_Course.*, dbo.Instructor.*
FROM dbo.Class INNER JOIN
dbo.Course_Class ON dbo.Class.ClassID = dbo.Course_Class.ClassID INNER JOIN
dbo.Course ON dbo.Course_Class.CourseID = dbo.Course.CourseID INNER JOIN
dbo.Inst_Course ON dbo.Course.CourseID = dbo.Inst_Course.CourseID INNER JOIN
dbo.Instructor ON dbo.Inst_Course.InstID = dbo.Instructor.InstructorID
WHERE (dbo.Inst_Course.InstID = 1)
I get 4 rows as result of query i see it is wrong it must be 2 rows . Are my result is wrong or true ?
我得到4行作为查询结果我发现它是错误的必须是2行。我的结果是错误的还是真的?
Result of query is wrong or true
查询结果错误或为真
1 个解决方案
#1
0
Your results are correct. 1) there aren't any duplicate rows in your results. 2) You can double check this by looking at your source tables. There are 2 Course IDs for instructor 1 in Inst_Course (1 and 2) which correspond to 4 rows in Course_Class (see CourseID column, there are 3 "1" time slots and 1 "2" time slots).
你的结果是正确的。 1)结果中没有任何重复的行。 2)您可以通过查看源表来仔细检查这一点。 Inst_Course(1和2)中的教师1有2个课程ID,对应于Course_Class中的4行(参见CourseID列,有3个“1”时隙和1个“2”时隙)。
#1
0
Your results are correct. 1) there aren't any duplicate rows in your results. 2) You can double check this by looking at your source tables. There are 2 Course IDs for instructor 1 in Inst_Course (1 and 2) which correspond to 4 rows in Course_Class (see CourseID column, there are 3 "1" time slots and 1 "2" time slots).
你的结果是正确的。 1)结果中没有任何重复的行。 2)您可以通过查看源表来仔细检查这一点。 Inst_Course(1和2)中的教师1有2个课程ID,对应于Course_Class中的4行(参见CourseID列,有3个“1”时隙和1个“2”时隙)。