gpt4 book ai didi

mysql - 如何从一个表中选择不应存在其他记录的记录

转载 作者:行者123 更新时间:2023-11-29 19:11:51 26 4
gpt4 key购买 nike

我有两张 table 。 subjectTbl 和SubjectAllotTbl。

这是我的主题表

+------------+--------------+---------------------+--------------+--------+----------+
| 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_id不应出现在SubjectAllotTbl中

我正在使用 MySql

最佳答案

select subject_name
from SubjectTbl
where subject_id not in ( select distinct subject_id from SubjectAllotTbl)

您可能不需要不同的,除非 subject_id 在不同的 Teacher_id 的SubjectAllotTbl 中重复

关于mysql - 如何从一个表中选择不应存在其他记录的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43020517/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com