2013-10-07 135 views
0

如何將第一個查詢的結果與第二個查詢合併,其中Z_EMP_YAN表和Z_OPRDEFN表的EMPLID列匹配?將2個查詢合併到1個查詢中

select b.OPRID 
from Z_EMP_BENFT a, PSOPRDEFN b 
WHERE a.EMPLID = b.EMPLID 
AND A.Z_PEND_COVER = 'Y' 
AND OPRID LIKE 'ZZ%' 

select EMPLID from z_emp_yan where z_yan_action_id = 1 

回答

2

試試這個

SELECT b.oprid 
FROM ps_z_emp_benft a, 
     psoprdefn b, 
     ps_z_emp_yan c 
WHERE a.emplid = b.emplid 
     AND a.emplid = c.emplid 
     AND A.z_pend_cover = 'Y' 
     AND oprid LIKE 'ZZ%' 
     AND c.z_yan_action_id = 1 
3

真的沒什麼錯上一篇文章中,我只喜歡用Joins

select b.oprid 
from ps_z_emp_benft a 
    join psoprdefn b on a.emplid = b.emplid 
    join ps_z_emp_yan c on a.emplid = c.emplid 
where A.z_pend_cover = 'Y' 
    and oprid LIKE 'ZZ%' 
    and c.z_yan_action_id = 1