桌子tblSubject
| 子識別符號 | 子名 |
|---|---|
| 1 | 數學 |
| 2 | 英語 |
桌子tblTeachers
| 教師編號 | 老師的名字 |
|---|---|
| 1 | 讓 |
| 2 | 瑪麗 |
桌子tblStudent
| 學生卡 | 學生姓名 |
|---|---|
| 1 | 愛德華 |
| 2 | 勞倫 |
桌子tblStudentSubMap
| ID | 學生卡 | 教師編號 | 子識別符號 |
|---|---|---|---|
| 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 |
我正在嘗試獲得以下輸出,但無法使用各種內部連接等
嘗試查詢:
SELECT tblsubject.subname, tblTeachers.teacherName
FROM tablesubject, tblteachers
WHERE tblStudentSubMap.studentId=1
WHERE條件輸入應為,studentid并回傳對應的學科名和教師名。
輸出
| ID | 表主題 | 老師的名字 |
|---|---|---|
| 1 | 數學 | 讓 |
| 2 | 英語 | 瑪麗 |
對于 Studentid = 1
uj5u.com熱心網友回復:
加入表格有多種方法,但您可以嘗試我的以下代碼
//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
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/474934.html
上一篇:在sql中加入兩個大查詢
