这是我的表格列表:
tblsection
tblgradelevel
tblteachers
我的tblsection
包含:
Section_ID | GradeID | sectionname | TeacherID
我的问题是如何在GradeID
中关联TeacherID
和tblsection
。
我tblsection
中的外键是:
Foreign key name | Reference table | Column | Reference Column
Section_GradeID | 'database','tblgradelevel' | GradeID | GradeID
Section_TeacherID |'database','tblteacher' | TeacherID| Teacher_ID
我使用许多查询来执行此问题,但它不起作用。
这是我的疑问:
"SELECT
a.Section_ID AS ID,
a.Sectionname AS SName,
b.GradeLevel AS Level,
c.TeacherID as Teach
FROM tblsection
INNER JOIN tblGradelevel b ON a.GradeID = b.GradeID";
我该怎么做?
答案 0 :(得分:0)
**The query will generate errors due to invalid alias for the table name tblsection **
Try below query:
SELECT
a.Section_ID AS ID,
a.Sectionname AS SName,
b.GradeLevel AS Level,
c.TeacherID as Teach
FROM tblsection a
INNER JOIN tblGradelevel b ON a.GradeID = b.GradeID
INNER JOIN tblteachers c ON a.TeacherID = c.TeacherID
答案 1 :(得分:0)
$sql="select a.Section_ID, a.Sectionname, b.GradeLevel, c.TeacherID from tblsection a INNER JOIN tblgradelevel b ON a.GradeID=b.GradeID INNER JOIN tblteachers c On a.GradeID=c.TeacherID";
这两个值必须相同,例如a.gradeID=b.gradeId
,然后才会执行查询。
我不会检查这个,但我正在用这种方式来处理我的应用程序。