select*from tbl_dept a innerjoin tbl_emp b on a.id=b.deptId;select*from tbl_dept a leftjoin tbl_emp b on a.id=b.deptId;select*from tbl_dept a rightjoin tbl_emp b on a.id=b.deptId;select*from tbl_dept a rightjoin tbl_emp b on a.id=b.deptId
unionselect*from tbl_dept a leftjoin tbl_emp b on a.id=b.deptId;
select*from tbl_dept a leftjoin tbl_emp b on a.id=b.deptId where b.deptId isnull;
select*from tbl_dept a
rightjoin tbl_emp b on a.id= b.deptId
where a.id isnullunionselect*from tbl_dept a
leftjoin tbl_emp b on a.id= b.deptId
where b.deptId isnull;
连子表
SELECT a.total1 as total,a.UID from(SELECTSUM(`amount`)as total1,`to_userid`as UID
FROM`t_diamond_cost_log`WHERE`user_id`=1640641and`type`=1and`to_userid`<>1and`cdate`>"2019-07-16 00:00:00"GROUPBY`to_userid`)as a
leftjoin(SELECTSUM(`amount`)as total2,`user_id`as UID
FROM`t_diamond_cost_log`WHERE`to_userid`=1640641and`type`=1and`user_id`<>1and`cdate`>"2019-07-16 00:00:00"GROUPBY`user_id`)as b
ON a.UID= b.UID