-----as - is
select
OD_NO ,
OD_PRGS_STEP_CD ,
ERR_LOG_CNTS ,
REG_DTTM
from
OM_OD_CNTN_STAT_HST
where
OD_NO in (
select
OD_NO
from
OM_OD_DTL
where
OD_NO between '20211022' and '20211023'
and OD_CNTN_PRGS_STAT_CD = '90'
and OD_TYP_CD = '10'
and TR_GRP_CD = 'LI' )
and (API_ID = 'OP_IF_0001'
or API_ID = 'OP_API_0002')
and instr(left(ERR_LOG_CNTS, 35), '정상') = 0;
----to - be
SELECT
A.OD_NO,
A.OD_PRGS_STEP_CD ,
A.ERR_LOG_CNTS ,
A.REG_DTTM
from
OM_OD_CNTN_STAT_HST A join OM_OD_DTL B on A.OD_NO=B.OD_NO
where B.OD_NO between '20211022' and '20211023'
and B.OD_CNTN_PRGS_STAT_CD = '90'
and B.OD_TYP_CD = '10'
and B.TR_GRP_CD = 'LI'
and (A.API_ID = 'OP_IF_0001' or A.API_ID = 'OP_API_0002')
and instr(left(A.ERR_LOG_CNTS, 35), '정상') = 0;
in절 쿼리를 join으로 변경하였는데 데이터 건수가 다릅니다.. join으로 바꾼흐 데이터가 더 나오는데 이럴경우가 있을까요?
-- 테이블 관계가 1:N 이면 조인 관계만큼 늘어나니까 건 수 맞춰야 하면 그룹핑 같은 추가 작업이 필요할꺼예요 -- WHERE IN 1 건 SELECT A.OD_NO FROM ( SELECT 1 AS OD_NO ) A WHERE OD_NO IN ( SELECT OD_NO FROM ( SELECT 1 OD_NO , 1 TR_GRP_CD UNION ALL SELECT 1 OD_NO , 2 TR_GRP_CD ) B ) -- JOIN ON 2 건 SELECT A.OD_NO -- , B.OD_NO, B.TR_GRP_CD FROM ( SELECT 1 AS OD_NO ) A JOIN ( SELECT 1 OD_NO , 1 TR_GRP_CD UNION ALL SELECT 1 OD_NO , 2 TR_GRP_CD ) B ON A.OD_NO = B.OD_NO