外连接内连接(编码)

鸣谢: https://blog.csdn.net/plg17/article/details/78758593


CREATE TABLE `a_table` (
  `a_id` int(11) DEFAULT NULL,
  `a_name` varchar(10) DEFAULT NULL,
  `a_part` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `b_table` (
  `b_id` int(11) DEFAULT NULL,
  `b_name` varchar(10) DEFAULT NULL,
  `b_part` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
insert into b_table value(2,"老王","秘书部");
insert into b_table value(3,"老张","设计部");
insert into b_table value(5,"老刘","人事部");
insert into b_table value(6,"老黄","生产部");

insert into a_table value(1,"老潘","总裁部");
insert into a_table value(2,"老王","秘书部");
insert into a_table value(3,"老张","设计部");
insert into a_table value(4,"老李","运营部");
外连接内连接(编码)_第1张图片
image.png

内连接:

select * from a_table a inner join b_table b on a.a_id = b.b_id;

外连接内连接(编码)_第2张图片
image.png
外连接内连接(编码)_第3张图片
image.png

外连接:

左连接:
select * from a_table a left join b_table bon a.a_id = b.b_id;

外连接内连接(编码)_第4张图片
image.png

外连接内连接(编码)_第5张图片
image.png

你可能感兴趣的:(外连接内连接(编码))