oracle左外连接不显示空值但显示相同的值

时间:2014-09-26 07:29:29

标签: oracle

问题在于左外连接,当右侧表中没有行然后它不显示null值时,它显示以前的值....

喜欢这个......

第1表包含

PGMTX_CODE    PGMTX_MARKS    PGMTX_TOTQSTN
-------------------------------------------
EE            1              5

EE            2              5

EE            3              0

EE            4              0

第二表包含

PGMTX_CODE    PGMTX_MARKS    PGMTX_ACTUSEDQST
-------------------------------------------
EE            1              5

所以我想要结果......

PGMTX_MARKS    PGMTX_TOTQSTN     PGMTX_ACTUSEDQST
--------------------------------------------------
1              5                 5

2              5                 blank

3              0                 blank

4              0                 blank 

我使用这样的查询...

SELECT m.PGMTX_MARKS, 
       m.PGMTX_TOTQSTN, 
       tlm.PGMTX_ACTUSEDQST, 
  from PAPERGEN_MTL_OEX m 
       left OUTER JOIN  PAPERGEN_TLMTL_OEX tlm 
         ON m.PGMTX_CODE=tlm.PGMTX_CODE
 where m.PGMTX_CODE='EE' 
 order by m.PGMTX_MARKS     

但我得到的结果如

PGMTX_MARKS    PGMTX_TOTQSTN     PGMTX_ACTUSEDQST
--------------------------------------------------
1              5                 5

2              5                 5

3              0                 5

4              0                 5      

1 个答案:

答案 0 :(得分:3)

您的加入条件错误,应该是

ON m.PGMTX_CODE=tlm.PGMTX_CODE AND m.PGMTX_MARKS = tlm.PGMTX_MARKS