select distinct studentid from tab2 t where (select count(*) from tab1 where teacherid = 1) =
(select count(*) from tab2 where subjectid in (select subjectid from tab1 where teacherid = 1)
and studentid = t.studentid
);
(select count(*) from tab2 where subjectid in (select subjectid from tab1 where teacherid = 1)
and studentid = t.studentid
);
select * from tab1 t2 where t2.teacherid=1 and not exists(
select * from tab2 t3 where t2.subjectid=t3.subjectid and t3.studentid=t1.studentid))