MySQL JOINs - 没有结果

时间:2014-03-13 21:18:48

标签: mysql join

我很确定它与我的选择表或连接的顺序有关,但是在我的查询中尝试了各种重新排序,我仍然坚持0结果。

有人能指出我正确的方向吗?

图表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%'

我很感激反馈!

1 个答案:

答案 0 :(得分:1)

JOIN表示INNER JOIN

在这种情况下,当您加入patient表时,它会尝试从person_id person表中的person_id表中查找patient。因此,此处唯一的可能性是,在person_id表的patient列中未找到前一个联接集中的person_id。所以有0条记录!