标签:select name table src 才有 rom inf default set
CREATE TABLE emp
(
id
int NOT NULL AUTO_INCREMENT,
name
varchar(255) DEFAULT NULL,
dept_id
int DEFAULT NULL,
PRIMARY KEY (id
)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
INSERT INTO emp
VALUES (1, ‘小红‘, 1);
INSERT INTO emp
VALUES (2, ‘小明‘, 2);
INSERT INTO emp
VALUES (3, ‘老王‘, 100);
CREATE TABLE dept
(
id
int NOT NULL AUTO_INCREMENT,
name
varchar(255) DEFAULT NULL,
PRIMARY KEY (id
)
) ENGINE=InnoDB AUTO_INCREMENT=101 DEFAULT CHARSET=utf8;
INSERT INTO dept
VALUES (1, ‘开发部‘);
INSERT INTO dept
VALUES (2, ‘运营部‘);
INSERT INTO dept
VALUES (3, ‘编辑部‘);
数据准备完毕
select
*
FROM emp e
inner join dept d
on e.dept_id = d.id
select * FROM emp left join dept on emp.dept_id = dept.id UNION select * FROM emp right join dept on emp.dept_id = dept.id
select * FROM emp left join dept on emp.dept_id = dept.id
select * FROM emp right join dept on emp.dept_id = dept.id
select
*
FROM emp e
left join dept d
on e.dept_id = d.id
where d.id is NULL
select
*
FROM emp e
right join dept d
on e.dept_id = d.id
where e.id is NULL
select
*
FROM emp e
left join dept d
on e.dept_id = d.id
where d.id is NULL
UNION
select
*
FROM emp e
right join dept d
on e.dept_id = d.id
where e.id is NULL
标签:select name table src 才有 rom inf default set
原文地址:https://www.cnblogs.com/z-sir/p/13874531.html