-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinner_join.sql
50 lines (33 loc) · 1.06 KB
/
inner_join.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
DROP TABLE IF EXISTS departments_dup;
CREATE TABLE departments_dup (
dept_no CHAR(4) NULL,
dept_name VARCHAR(40) NULL
);
INSERT INTO departments_dup
(
dept_no,
dept_name
)SELECT * FROM departments;
INSERT INTO departments_dup (dept_name) VALUES ('Public Relations');
DELETE FROM departments_dup WHERE dept_no = 'd002';
INSERT INTO departments_dup(dept_no) VALUES ('d010'), ('d011');
select * from departments_dup order by dept_no;
DROP TABLE IF EXISTS dept_manager_dup;
CREATE TABLE dept_manager_dup (
emp_no int(11) NOT NULL,
dept_no char(4) NULL,
from_date date NOT NULL,
to_date date NULL
);
INSERT INTO dept_manager_dup
select * from dept_manager;
INSERT INTO dept_manager_dup (emp_no, from_date)
VALUES (999904, '2017-01-01'),
(999905, '2017-01-01'),
(999906, '2017-01-01'),
(999907, '2017-01-01');
DELETE FROM dept_manager_dup
WHERE dept_no = 'd001';
select * from dept_manager_dup;
select dm.dept_no, dm.emp_no, dp.dept_name from departments_dup dp
join dept_manager_dup dm on dm.dept_no=dp.dept_no order by dm.dept_no;