2020年11月13日:
关于子查询
查询结果作为外层查询的条件或结果集。
例如:
学生学科表 s_subject
学生学科成绩表:s_subject_score
select * from s_subject_score ste where ste.s_suject_id in (select st.id from s_subject st where st.studentid = ?) and ste.studentid = ?;
特点:无关子查询往往先执行且只执行一次,并将结果提供给外层查询作为条件或结果集。
二、相关子查询
select (select st.SUBJECT_NAME ST.id = s.SUBJECTID from subject st) subjectName,--相关子查询
STE.SCORE score from s_subject_score ste,s_subject s where ste.s_suject_id in (select st.id from s_subject st where st.studentid = ?)--无关子查询 and ste.studentid = ?;