【发布时间】:2014-07-28 16:08:27
【问题描述】:
昨晚我有一个问题,以确保我已正确格式化我的 php,以确保我能够测试查询。今天在 mysql workbench 工作时,我发现我无法得到我想要的所有结果。我的“联系人”表中目前有 15 行,但是当我运行以下代码时,只有 8 行通过。请注意,我正在使用多个表格,但其中一些表格每个联系人的行数不止一行,而在同一个表格中,有些表格中的某些表格没有行,而其他表格则有多个表格。
SELECT
`Contact`.`firstName`,
`Contact`.`lastName`,
`ssn`.`ssn`,
`Contact`.`country`,
`Allergies`.`allergy`,
`Allergies`.`allergyType`,
`Allergies_Contact`.`allergyNotes`,
`CurrentPrescriptions`.`prescriptionName`,
`CurrentPrescriptions`.`prescribedDate`,
`BloodType`.`bloodType`
FROM
`mher`.`Contact`,
`mher`.`Allergies_Contact`,
`mher`.`Allergies`,
`mher`.`ssn`,
`mher`.`CurrentPrescriptions`,
`mher`.`BloodType`
WHERE
`Contact`.`contactKey` = `Allergies_Contact`.`contactKey`
AND `Allergies`.`allergiesKey` = `Allergies_Contact`.`allergiesKey`
AND `ssn`.`contactKey` = `Contact`.`contactKey`
AND `CurrentPrescriptions`.`contactKey` = `Contact`.`contactKey`
AND `BloodType`.`contactKey` = `Contact`.`contactKey`;
【问题讨论】:
-
我们有机会看到你的表结构吗?
-
@JonH 这些是默认的 MySQL 转义字符,大多数数据库使用
[],mysql 使用`` -
将 db 结构添加到 main
-
重新阅读您的问题后,听起来您想要某些表格没有结果的条目,这是正确的,如果是,哪些表格?
-
这是正确的,过敏表(Allergies 和 Allergy_Contact)和处方表
标签: mysql select where mysql-workbench