-1

I have a table District(Parent table) and college (Child table) which are connected with one-to-many, one District may have multiple Colleges. Here district_id acts as a Foreign key in the College table. I am trying to retrieve districts which doesn't have any colleges associated with it using the below query but it doesn't give the correct results

select * from district where district_id not in (select district_id from college)

enter image description here

Hirein
  • 135
  • 5
  • 20

1 Answers1

1

You can use a left join between distrct and collegeand che for not matching key

select distinct d.* 
from district d
left join college c on c.district_id = d.district_id 
where c.district_id is null
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107