首页 > 代码库 > mysql left join,right join,inner join简单实例
mysql left join,right join,inner join简单实例
-- 准备工作
drop table if exists Emp;
create table if not exists Emp
(
uid int primary key,
sid int
);
insert into Emp values(1,1);
insert into Emp values(2,2);
drop table if exists Sal;
create table if not exists Sal
(
sid int primary key,
salary float
);
insert into Sal values(1,11);
insert into Sal values(3,33);
-- 查看结果
select * from Emp left join Sal on Emp.sid = Sal.sid;
左表为主(左表内容至少全部出现一次)
uid | sid | sid | salary |
1 | 1 | 1 | 11 |
2 | 2 | NULL | NULL |
select * from Emp right join Sal on Emp.sid = Sal.sid;
右表为主(右表内容至少全部出现一次)
uid | sid | sid | salary |
1 | 1 | 1 | 11 |
NULL | NULL | 3 | 33 |
select * from Emp inner join Sal on Emp.sid = Sal.sid;
相当于上面两表求交集
uid | sid | sid | salary |
1 | 1 | 1 | 11 |
mysql left join,right join,inner join简单实例
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。