我正在尝试用3个以上的表构建查询,其中数据散布在
表tblSubject
subid | 子名 |
---|---|
1 | 数学 |
2 | 英语 |
表tblTeachers
thockerid | thockername |
---|---|
1 | Jean |
2 Jean 2 | Mary |
Table TBLSTUDENT
StudentId studentId | studentname |
---|---|
1 | Edward |
2 | Lauren |
Table 2 Lauren Table> code> tblstudentsubmapmap
id | studentId | 教师 | subid |
---|---|---|---|
1 | 1 | 1 | 1 |
1 2 | 2 | 1 | 1 |
3 | 1 | 2 | 1 |
2 | 1 4 2 | 2 | 1 |
5 | 1 | 5 1 | 2 |
6 | 2 | 1 2 | 1 2 |
7 | 2 | 2 | 2 |
我试图获得以下输出,但无法使用各种内部的内部输出加入ETC
尝试查询:
SELECT tblsubject.subname, tblTeachers.teacherName
FROM tablesubject, tblteachers
WHERE tblStudentSubMap.studentId=1
其中
条件输入应为StudentId
,应返回相应的主题名称和老师名称。
输出
ID | tablesubject | thockername |
---|---|---|
1 | 数学 | Jean |
2 | English | Mary |
for StudentId = 1
Table tblSubject
subId | subName |
---|---|
1 | Mathematics |
2 | English |
Table tblTeachers
teacherId | teacherName |
---|---|
1 | Jean |
2 | Mary |
Table tblStudent
studentId | studentName |
---|---|
1 | Edward |
2 | Lauren |
Table tblStudentSubMap
Id | studentId | teacherId | subId |
---|---|---|---|
1 | 1 | 1 | 1 |
2 | 2 | 1 | 1 |
3 | 1 | 2 | 1 |
4 | 2 | 2 | 1 |
5 | 1 | 1 | 2 |
6 | 2 | 1 | 2 |
7 | 2 | 2 | 2 |
I am trying to get the below output but unable to with various inner joins etc
Attempted query:
SELECT tblsubject.subname, tblTeachers.teacherName
FROM tablesubject, tblteachers
WHERE tblStudentSubMap.studentId=1
The WHERE
condition input should be studentid
and the corresponding subject name and teacher name should be returned.
Output
id | tablesubject | teacherName |
---|---|---|
1 | Mathematics | Jean |
2 | English | Mary |
for Studentid = 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
连接表有各种各样的方法,但是您可以尝试我的下面代码
There are various method on joining tables but you can try my below code