delete from `study_groups` WHERE GradeID in ( select id from grades where Degree not in ('bachelor', 'specialist', 'master') ); delete from grades where Degree not in ('bachelor', 'specialist', 'master');