我有一個查詢可以獲取有關用戶的信息。用戶可能沒有,一個或多個電話號碼。我想要做的是將用戶的最新電話號碼(由seq編號確定)與其他基本人口統計數據一起加入到查詢中。我面對的問題是如果我的子查詢返回null,用戶不會顯示在我的查詢中。我如何處理子查詢中的空值,以便這些行仍然返回?使用返回null的子查詢進行查詢
SELECT SPRIDEN.SPRIDEN_ID AS Student_ID ,
saradap.SARADAP_APST_CODE ,
saradap.SARADAP_PIDM ,
spriden.spriden_first_name ,
spriden.spriden_last_name ,
saradap.saradap_program_1 ,
spraddr.SPRADDR_STREET_LINE1 ,
spraddr.spraddr_city ,
spraddr.spraddr_zip ,
spraddr.spraddr_stat_code ,
saradap.SARADAP_APPL_DATE ,
'Individual' AS Account_Name ,
saradap.SARADAP_CAMP_CODE ,
CONCAT(sprtele_phone_area, sprtele_phone_number) "Phone" ,
sprtele_tele_code ,
sorcont_ctyp_code ,
sorcont_contact_date ,
sorcont.sorcont_activity_date
FROM saradap
LEFT JOIN spriden ON saradap.saradap_pidm = spriden_pidm
LEFT JOIN spraddr ON saradap.saradap_pidm = spraddr.spraddr_pidm
LEFT JOIN sprtele ON saradap.saradap_pidm = sprtele.sprtele_pidm
LEFT JOIN sorcont ON saradap.saradap_pidm = sorcont.sorcont_pidm
WHERE spriden.spriden_change_ind IS NULL
AND (saradap.SARADAP_CAMP_CODE = 'D'
OR saradap.SARADAP_CAMP_CODE = 'JD'
)
AND saradap.saradap_appl_date > SYSDATE - 15
AND spraddr.spraddr_seqno = (SELECT MAX(spraddr.spraddr_seqno)
FROM spraddr
WHERE saradap.SARADAP_PIDM = spraddr.spraddr_pidm
)
AND sprtele_seqno = (SELECT MAX(SPRTELE_SEQNO)
FROM SATURN.SPRTELE
WHERE sprtele_pidm = saradap.saradap_pidm
)