▶ 서브쿼리란?
: 쿼리문 내에 또 다른 쿼리문이 있는 것을 말한다.
( 서브쿼리는 괄호를 묶어서 사용해야 하고, 서브쿼리 내에서 order by 절은 사용할 수 없다. )
▶ select 내에서 서브쿼리 사용
: select 내에서 서브쿼리 사용시 서브쿼리 결과값은 하나만 출력되야 한다.
select
member_no,
(select count(*) from tb_inquire
where a.contents_no=contents_no and a.member_no=member_no) inquire_count
from (
select
t3.contents_no, t1.member_no
from tb_contents_attend t1
inner join tb_member t2 on t1.member_no=t2.member_no
inner join tb_contents t3 on t1.contents_no=t3.contents_no
group by t3.contents_no, t1.member_no
) as a
group by member_no, contents_no
728x90
'Database' 카테고리의 다른 글
SQL 알아보기 (0) | 2022.12.07 |
---|---|
[oracle] null 처리하기 (NVL, NVL2 함수) (0) | 2022.11.30 |
JOIN (0) | 2021.09.08 |
[mysql] 값이 없으면 insert 있으면 update (0) | 2021.07.09 |
MERGE문 사용해 INSERT, UPDATE 처리하기 (0) | 2021.06.29 |