为什么同一行显示2次?

时间:2016-05-26 13:43:40

标签: sql

SELECT patient.P_ID, patient.P_NAME, patient.P_AGE, 
       patient.P_GENDER, patient.ADDRESS, patient.DOA, 
       patient.P_ID DIAGNOSE
FROM patient,presciption
WHERE patient.P_ID != presciption.P_ID

1 个答案:

答案 0 :(得分:2)

只要在预告表中找不到患者,请使用NOT EXISTS返回患者:

select patient.P_ID, patient.P_NAME, patient.P_AGE, patient.P_GENDER, patient.ADDRESS, patient.DOA, patient.P_ID DIAGNOSE
from patient
where not exists (select 1 from presciption
                  where patient.P_ID = presciption.P_ID)