I have joined two tables using inner join. Here primary key of table TPREG is co_id and pol_id
SELECT (SELECT etbl_desc_txt
FROM uding604.tedit e
WHERE etbl_typ_id = 'PITCD'
AND co_id = 'CP'
AND etbl_valu_id = p.pol_ind_typ_cd) pol_ind_typ_cd,
(SELECT etbl_desc_txt
FROM uding604.tedit e
WHERE etbl_typ_id = 'PAYT'
AND co_id = 'CP'
AND etbl_valu_id = p.POL_BILL_TYP_CD) POL_BILL_TYP_CD,
POL_PAC_DRW_DY,
(SELECT etbl_desc_txt
FROM uding604.tedit e
WHERE etbl_typ_id = 'PAYM'
AND co_id = 'CP'
AND etbl_valu_id = p.POL_BILL_MODE_CD) POL_BILL_MODE_CD,
t.SOURCE_CD
FROM uding604.tpol p,
uding604.TPREG t
WHERE p.co_id = t.co_id
AND p.pol_id = t.pol_id
AND p.co_id = 'CP'
AND p.pol_id = '000000011'
AND t.co_id = 'CP'
AND t.pol_id = '000000011'
How to make this query more simple?
Please guide.
You can transform the subqueryes to joins:.
The query is clearer on
selectclause but is fuzzy atWhereclause.What we can do is to move on ANSI JOIN syntax:
Now is clearer what you want.
Note1. You may try to remove
because is not logic necessarly.
Note2. You must test if these queryes return the same as your query.
Note3. You should allways use ANSI JOIN syntax, will help you when you not expect it.