输入banner图图片脚本导航/分类

MYSQL 的七种join

文氏图与SQL语句的编写以及查询结果

内连接

内连接文氏图

技术图片

执行的sql语句以及执行的查询结果

  • 执行的sql语句
select * from tbl_dept a inner join tbl_emp b on a.id=b.deptId;
  • 查询结果 
    技术图片

左外连接

左外连接文氏图

技术图片

执行的sql语句以及执行的查询结果

  • 执行的sql语句
select * from tbl_dept a left join tbl_emp b on a.id=b.deptId;
  • 查询结果 
    技术图片

右外连接

右外连接文氏图

技术图片

执行的sql语句以及执行的查询结果

  • 执行的sql语句
select * from tbl_dept a right join tbl_emp b on a.id=b.deptId;
  • 查询结果 
    技术图片

左连接

左连接文氏图

技术图片

执行的sql语句以及执行的查询结果

  • 执行的sql语句
elect * from tbl_dept a left join tbl_emp b on a.id=b.deptId where b.deptId is null;
  • 查询结果

技术图片

右连接

右连接文氏图

技术图片

执行的sql语句以及执行的查询结果

  • 执行的sql语句
select * from tbl_dept a right join tbl_emp b on a.id=b.deptId where a.id is null;
  • 查询结果

技术图片

全连接

全连接文氏图

技术图片

执行的sql语句以及执行的查询结果

  • 执行的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语句以及执行的查询结果

  • 执行的sql语句
select * from tbl_dept a right join tbl_emp b on a.id=b.deptId where a.id is null union select * from tbl_dept a left join tbl_emp b on a.id=b.deptId where b.deptId is null;
  • 查询结果

技术图片

   

MYSQL 的七种join

标签:fun   insert   clist   block   str   top   执行   左连接   查询