我有两张桌子。 SubjectTbl和SubjectAllotTbl。
这是我的SubjectTbl
+------------+--------------+---------------------+--------------+--------+----------+
| Subject_Id | Subject_Code | Subject_Name | Periods_Week | Dep_Id | Semester |
+------------+--------------+---------------------+--------------+--------+----------+
| 1 | 6012 | Basic Electronics | 10 | 1 | 1 |
| 2 | 5412 | Computer Science | 7 | 1 | 3 |
| 3 | 1421 | Musical Science | 4 | 1 | 5 |
| 4 | 547 | Network Programming | 7 | 1 | 5 |
+------------+--------------+---------------------+--------------+--------+----------+
和SubjectAllotTbl
+------------+------------+
| Subject_Id | Teacher_Id |
+------------+------------+
| 1 | 1 |
| 2 | 3 |
| 3 | 2 |
+------------+------------+
我要做的就是从表SubjectTbl中选择Subject_Name,其中Subject_lotTbl中不应出现相同的subject_id
我正在使用MySql
最佳答案
select subject_name
from SubjectTbl
where subject_id not in ( select distinct subject_id from SubjectAllotTbl)
您可能不需要区分,除非subject_id在SubjectAllotTbl中针对不同的Teacher_id重复