select * from tbl_emp a inner join tbl_dept b on a.deptId=b.id;
select * from tbl_emp a LEFT JOIN tbl_dept b on a.deptId=b.id;
select * from tbl_emp a RIGHT JOIN tbl_dept b on a.deptId=b.id;
select * from tbl_emp a LEFT JOIN tbl_dept b on a.deptId=b.id where b.id is null;
select * from tbl_emp a RIGHT JOIN tbl_dept b on a.deptId=b.id where a.id is null;
select * from tbl_emp a LEFT JOIN tbl_dept b on a.deptId=b.id union select * from tbl_emp a RIGHT JOIN tbl_dept b on a.deptId=b.id;
select * from tbl_emp a LEFT JOIN tbl_dept b on a.deptId=b.id where b.id is null union select * from tbl_emp a RIGHT JOIN tbl_dept b on a.deptId=b.id where a.id is null;
mysql 7种JOIN理论,看完你就懂了
最新推荐文章于 2024-04-25 16:08:10 发布