我需要帮助优化此SQL查询。SQL查询查找表记录是同一表的一部分
我有一个表叫Student
有以下栏目:
id; Department_Name; Parent_Department
值如:
id Department_Name Parent_Department
1 IT_CS
2 IT_BP
3 IT_NP
4 IT1 1
5 IT2 1
6 IT3 3
7 IT4
8 IT9 2
我需要的是让从表中的所有id其中parent_department = IT_CS; 为了这个,我正在写2查询
select id from student where Department_Name ='IT_CS';
select id from student where parent Parent_Department =Id
从上面的查询进账;
有没有更好的方法来做到这一点?