2014-03-13 52 views
0

我很確定它與我的選擇表或連接順序有關,但在查詢中嘗試了各種重新排序,我仍然堅持使用0結果。MySQL JOINs - 沒有結果

難道有人指着我正確的方向嗎?

圖表A(返回355次的結果):

SELECT DISTINCT 
    person.person_id as "Person ID", 
    CONCAT(person.last, ', ', person.first) as "Patient Name", 
    person.birthday as "Birthday", 
    person_ins_tie.insurance_id as "Insurance ID", 
    insurance.carrier as "Carrier", 
    insurance.phone as "Carrier Phone Number" 
FROM 
    person 
     JOIN 
    person_ins_tie ON person.person_id = person_ins_tie.person_id 
     JOIN 
    insurance ON person_ins_tie.insurance_id = insurance.insurance_id 
WHERE 
    insurance.carrier LIKE 'Blue%' 

圖表B(返回0的結果/沒有錯誤):

SELECT DISTINCT 
    person.person_id as 'Person ID', 
    patient.display_id as 'Chart #', 
    CONCAT(person.last, ', ', person.first) as 'Patient Name', 
    person.birthday as 'Birthday', 
    insurance.insurance_id as 'Insurance ID', 
    insurance.carrier as 'Carrier', 
    insurance.phone as 'Carrier Phone Number' 
FROM 
    person 
     JOIN 
    person_ins_tie ON person.person_id = person_ins_tie.person_id 
     JOIN 
    insurance ON person_ins_tie.insurance_id = insurance.insurance_id 
     JOIN 
    patient ON person.person_id = patient.person_id 
WHERE 
    insurance.carrier LIKE 'Blue%' 

我欣賞反饋!

+0

您是否檢查過在第一個查詢中的任何「人」在「patient」中是否存在匹配的「person_id」? – trogdor

+0

在此基礎上,我不能說太多,但檢查所有提到的表格(尤其是耐心,因爲它是差異)中的數據是否良好,並檢查列出的列(是否存在於相應的表格中)。 –

回答

1

JOIN表示INNER JOIN

在當你與patient表連接的這種情況下,它會嘗試找到person_idpersonpatientperson_id。所以這裏唯一的可能性是在patient表的person_id列中找不到前一個連接集的person_id。所以0記錄!