mysql的七种join

有这样两个表:


一、


sql语句:

select * from tbl_dept a inner join tbl_emp b on a.id = b.depId;


二、


sql语句:

select * from tbl_dept a left join tbl_emp b on a.id=b.deptId;

三、


sql语句

select * from tbl_dept a right join tbl_emp b on a.id = b.deptId;

四、


sql语句:

select * from tbl_dept a left join tbl_emp b on a.id=b.deptId where b.deptId is null;

五、


sql语句

select * from tbl_dept a right join tbl_emp b on a.id=b.deptId where a.id is null;

六、


sql语句

select * from tbl_dept a right join tbl_emp b on a.id=b.deptId

union

select * from tbl_dept a left join tbl_emp b on a.id=b.deptId;

七、


sql语句

select * from tbl_dept a right join tbl_emp b on a.id=b.depId where a.id is null 

union

select * from tbl_dept a left join tbl_emp b on a.id=b.depId where b.deptId is null;

猜你喜欢

转载自blog.csdn.net/DATA8866/article/details/80045952