我正在尝试用3个以上的表构建查询,其中数据散布在

发布于 2025-01-24 02:14:23 字数 1890 浏览 2 评论 0原文

tblSubject

subid子名
1数学
2英语

tblTeachers

thockeridthockername
1Jean
2 Jean 2Mary

Table TBLSTUDENT

StudentId studentIdstudentname
1Edward
2Lauren

Table 2 Lauren Table> code> tblstudentsubmapmap

idstudentId教师subid
1111
1 2211
3121
21 4 221
515 12
621 21 2
7222

我试图获得以下输出,但无法使用各种内部的内部输出加入ETC

尝试查询:

SELECT tblsubject.subname, tblTeachers.teacherName 
  FROM tablesubject, tblteachers 
WHERE tblStudentSubMap.studentId=1

其中条件输入应为StudentId,应返回相应的主题名称和老师名称。

输出

IDtablesubjectthockername
1数学Jean
2EnglishMary

for StudentId = 1

Table tblSubject

subIdsubName
1Mathematics
2English

Table tblTeachers

teacherIdteacherName
1Jean
2Mary

Table tblStudent

studentIdstudentName
1Edward
2Lauren

Table tblStudentSubMap

IdstudentIdteacherIdsubId
1111
2211
3121
4221
5112
6212
7222

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

idtablesubjectteacherName
1MathematicsJean
2EnglishMary

for Studentid = 1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉薄对峙 2025-01-31 02:14:23

连接表有各种各样的方法,但是您可以尝试我的下面代码

//Get columnName in every Table
SELECT map.Id,s.studentName,t.teacherName,sub.subName
FROM tblStudentSubMap map
LEFT JOIN tblStudent s ON s.studentID = map.studentID//Find Data with the same ID
LEFT JOIN tblTeacher t ON t.teacherID = map.teacherID//Find Data with the same ID
LEFT JOIN tblSubject sub ON sub.ID = map.subID;//Find Data with the same ID

There are various method on joining tables but you can try my below code

//Get columnName in every Table
SELECT map.Id,s.studentName,t.teacherName,sub.subName
FROM tblStudentSubMap map
LEFT JOIN tblStudent s ON s.studentID = map.studentID//Find Data with the same ID
LEFT JOIN tblTeacher t ON t.teacherID = map.teacherID//Find Data with the same ID
LEFT JOIN tblSubject sub ON sub.ID = map.subID;//Find Data with the same ID
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文