0

I have 2 tables. I want to get all students id from table A who never went to college. So result should only return "2" here.

Table A
Student ID
1
2
3
Table B
1 - School
1 - College
2 - School
3 - School
3 - College
eshirvana
  • 23,227
  • 3
  • 22
  • 38
Sanjay
  • 13
  • 2
  • Does this answer your question? [Find records on multiple fields not in another table](https://stackoverflow.com/questions/30296988/find-records-on-multiple-fields-not-in-another-table) – pwilcox Mar 03 '21 at 15:36

1 Answers1

1

one way is to use not exists which is the fastest if you are working with huge data:

select *
from TableA
where not exists ( select 1 from table2 
                   where table1.studentid = tableb.studentid 
                   and schoolcol = 'college'
                 )
eshirvana
  • 23,227
  • 3
  • 22
  • 38