Left Join基本语法:
SQL LEFT JOIN 关键字
LEFT JOIN 关键字会从左表 (table_name1) 那里返回所有的行,即使在右表 (table_name2) 中没有匹配的行。
LEFT JOIN 关键字语法
SELECT column_name(s) FROM table_name1 LEFT JOIN table_name2 ON table_name1.column_name=table_name2.column_name
注释:在某些数据库中, LEFT JOIN 称为 LEFT OUTER JOIN。
直接上实例,连续使用Left Join进行数据的筛选
SELECT B.CMC 门诊费用统计,A.IMZFYBM,C.CMC 门诊财务统计,A.IMZCWBM,D.CMC 住院费用统计,A.IZYFYBM,E.CMC 住院财务统计,A.IMZCWBM,* FROM YXHIS..TBZDYLXM A
LEFT JOIN YXHIS..TBZDFYTJMZ B ON A.IMZFYBM=B.IBM
LEFT JOIN YXHIS..TBZDCWTJMZ C ON A.IMZCWBM=C.IBM
LEFT JOIN YXHIS..TBZDFYTJ D ON A.IZYFYBM=D.IBM
LEFT JOIN YXHIS..TBZDCWTJ E ON A.IZYCWBM=E.IBM
WHERE (A.BENABLEMZ=1 OR A.BENABLE=1)