SQL Subquery
1) Scalar Subquery
2) Inline View
3) Nested Subquery
select 절에 사용하고 결과는 하나의 column
select select, (select * from db where condition)
from db
where condition
from 절에 사용하는 subquery
메인쿼리에서는 인라인 뷰에서 조회한 column만 사용 가능
select select
from db, (select * from db where condition)
where condition
where 절에 사용하는 subquery
1) single row
select select
from db
where condition = (select * from db where condition)
2) multiple row - in
select select
from db
where condition in (select * from db where condition)
2) multiple row - exists
select select
from db
where condition exists (select * from db where condition)
3) multiple row - any
select select
from db
where condition = any (select * from db where condition)
4) multiple row - all
select select
from db
where condition = all (select * from db where condition)
5) multiple column
서브쿼리 내에 메인쿼리 컬럼이 같이 사용되는 경우
select column1, column2, ---
from db
where (colum1, column2) in (select column1, column2 from db where condition)