美文网首页
MySql左连接的使用

MySql左连接的使用

作者: Suncy | 来源:发表于2022-04-11 15:49 被阅读0次
    ### 左连接会先查询出所有链接的表数据,之后再匹配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

    相关文章

      网友评论

          本文标题:MySql左连接的使用

          本文链接:https://www.haomeiwen.com/subject/waxssrtx.html