하나의 SQL 문 안에 포함되어 있는 또 다른 SQL 문을 말한다.
메인쿼리가 서브쿼리를 포함하는 종속적인 관계이다.
• 서브쿼리는 메인쿼리의 칼럼 사용 가능
• 메인쿼리는 서브쿼리의 칼럼 사용 불가
Subquery 는 괄호로 묶어서 사용
단일 행 혹은 복수 행 비교 연산자와 함께 사용 가능
subquery 에서는 order by 를 사용X
select column1, (select column2 from table2 where condition)
from table1
where condition;
예제 : 서울은평경찰서의 강도 검거 건수와 서울시 경찰서 전체의 평균 강도 검거 건수를 조회
select case_number,
(select avg(case_number)
from crime_status
where crime_type like '강도' and status_type like '검거')avg
from crime_status
where police_station like '은평' and crime_type like '강도' and status_type like '검거';

select a.column, b.column
from table a, (select column1, column2 from table2) b
where condition;
