-1

问题

我有四个需要从中提取信息的表,其中两个只是简单的连接。

我的查询没有返回任何内容。基本上,有一些表格我需要确保我从一张桌子和下一张桌子上绑定到我的病人,以便我提取表格名称,使其成为正确的表格。

我有的

select person.first, person.last, treatmentPlan.created, treatmentPlan.updated, treatmentPlan.provider_id, intake.created, intake.updated, assesment.created, assesment.updated, discharge.created, discharge.updated

from form_patient_tie intake
LEFT OUTER JOIN form_patient_tie treatmentPlan ON intake.patient_id = treatmentPlan.patient_id
LEFT OUTER JOIN form_patient_tie assesment ON intake.patient_id = assesment.patient_id
LEFT OUTER JOIN form_patient_tie discharge ON intake.patient_id = discharge.patient_id

JOIN form as intakeForm ON intakeForm.form_id = intake.form_id
LEFT OUTER JOIN form treatmentPlanForm ON treatmentPlan.form_id = treatmentPlanForm.form_id
LEFT OUTER JOIN form assesmentForm on assesment.form_id = assesmentForm.form_id
LEFT OUTER JOIN form dischargeForm on discharge.form_id = dischargeForm.form_id
JOIN patient ON intake.patient_id = patient.patient_id
JOIN person on patient.person_id = person.person_id

WHERE (treatmentPlanForm.form_name LIKE "%Counseling Treatment Plan%" OR treatmentPlanForm.form_name IS NULL)
AND (intakeForm.form_name LIKE "%Counseling Intake%" OR intakeForm.form_name IS NULL)
AND (assesmentForm.form_name LIKE "%Counseling Assesment Review%" OR assesmentForm.form_name IS NULL)
AND (dischargeForm.form_name LIKE "%Counseling Discharge%" OR dischargeForm.form_name IS NULL)

即使我知道有一位患者完成了入院、复查和评估,但没有出院,它也没有返回任何内容。如果他们拥有所有 4 个,它可以正常工作,但如果他们缺少一个,它不会。

它应该看起来像

John Doe 2013-01-13 2013-01-15 2013-02-13 等。绝对允许它们为空,因为不是每个人都会填写一个。

4

1 回答 1

0

在我看来,您对“表单”表(intakeForm 别名)的连接也应该是左连接。否则,如果摄入表单上没有匹配项,则整个查询将不返回任何内容。

于 2013-06-06T22:08:17.030 回答