### 左连接会先查询出所有链接的表数据,之后再匹配WHERE后面的条件:
SELECT u.name,u.id AS userId,u.gender,u.birthday,u.mobile,u.img,p.disease_info,pb.sn,pb.state
FROM (`user` u,`doctor_patient` d)
LEFT JOIN `patient_disease_info` p ON d.patient_user_id = p.user_id
LEFT JOIN patient_blood_pressure_bind_his pb ON d.patient_user_id = pb.user_id AND pb.deleted = 0
WHERE d.doctor_user_id = 'dffb19e2ebb94243b0275ce2b18482c0' AND u.id = d.patient_user_id AND
d.deleted = 0 AND u.deleted = 0
image.png
### 查出所有数据之后,可以使用AND匹配最终字段的数据情况:
SELECT u.name,u.id AS userId,u.gender,u.birthday,u.mobile,u.img,p.disease_info,pb.sn,pb.state
FROM (`user` u,`doctor_patient` d)
LEFT JOIN `patient_disease_info` p ON d.patient_user_id = p.user_id
LEFT JOIN patient_blood_pressure_bind_his pb ON d.patient_user_id = pb.user_id AND pb.deleted = 0
WHERE d.doctor_user_id = 'dffb19e2ebb94243b0275ce2b18482c0' AND u.id = d.patient_user_id AND
d.deleted = 0 AND u.deleted = 0 AND pb.state IS NOT NULL
image.png
网友评论