[SQL] Where In | JeongKeepsCalm

[SQL] Where In

where [column name] in (subquery)

1
2
3
4
5
6
7
select c.title, c.lv2Cd
from test c
where 1=1
  and c.lv2Cd in (
    select menu.lv2Cd from test menu 
    where menu.title = (select e.title from test e where e.mnCd = #{mnCd})
  );

subquery 를 in 절에 넣어 원하는 결과를 얻을 수 있다.