MySQL JOIN - 没有结果

标签 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%'

感谢您的反馈!

最佳答案

JOIN 表示INNER JOIN

在这种情况下,当您加入 patent 表时,它会尝试从 person 表中的 person_id 中查找 person_id patent 表的 >。因此,这里唯一的可能性是在 patent 表的 person_id 列中找不到前一个连接集中的 person_id。共有 0 条记录!

关于MySQL JOIN - 没有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22391130/

相关文章:

mysql - 返回所有父表行,但对于与 MYSQL 的 WHERE 子句不匹配的子表行返回 null

mysql - 获取连接表不起作用 codeigniter

Java, JDBC : Does closing a PreparedStatement also free up its memory footprint in the database connection?

php - MySQL连接表并获取一个表中不存在的结果

mysql表设计,分表还是全表?

mysql - 从一张表中删除外键上的字段小于MySQL中的值

java - 不包括 JOIN 的 Hibernate 条件

Python:在一行中拆分、剥离和连接

mysql- "column cannot be null"

mysql - 从库上的行锁定是否也适用于主库?