【发布时间】:2021-03-03 15:28:58
【问题描述】:
我有 2 张桌子。我想从表 A 中获取所有从未上过大学的学生 id。 所以结果应该只返回“2”。
Table A
Student ID
1
2
3
Table B
1 - School
1 - College
2 - School
3 - School
3 - College
【问题讨论】:
标签: sql sql-server
我有 2 张桌子。我想从表 A 中获取所有从未上过大学的学生 id。 所以结果应该只返回“2”。
Table A
Student ID
1
2
3
Table B
1 - School
1 - College
2 - School
3 - School
3 - College
【问题讨论】:
标签: sql sql-server
一种方法是使用not exists,如果您处理大量数据,这是最快的:
select *
from TableA
where not exists ( select 1 from table2
where table1.studentid = tableb.studentid
and schoolcol = 'college'
)
【讨论】: