Repository navigation
Expand file tree
/
Copy pathDay 16-2.sql
More file actions
79 lines (66 loc) · 1.48 KB
/
Copy pathDay 16-2.sql
File metadata and controls
79 lines (66 loc) · 1.48 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
CREATE DATABASE company;
USE company;
drop table employee;
CREATE TABLE employee (
EID INT AUTO_INCREMENT,
ENAME CHAR(100) NOT NULL,
CITY CHAR(50) NOT NULL,
PRIMARY KEY (EID)
);
CREATE TABLE department (
DID INT AUTO_INCREMENT,
DNAME CHAR(100) NOT NULL,
EID INT,
PRIMARY KEY (DID)
);
insert into employee(ENAME, CITY)
values
("Harsh", "Vadodara"),
("Sachin", "Mumbai"),
("Vaishali", "Delhi"),
("Charu", "Indore"),
("Bhupendra", "Kashmir");
insert into department(DNAME, EID)
values
("HR", 5),
("CSE", 2),
("Sales", 3),
("Marketing", 4),
("PR", 1),
("IT", 6),
("R&D", 7);
-- Inner Join
Syntax -
select col_name(s)
FROM table_1
INNER JOIN table_2
ON table_1.col_name = table_2.col_name;
select * from employee
INNER JOIN department
ON employee.EID = department.EID;
-- LEFT JOIN & Left Inner Join
select * from employee
LEFT JOIN department
ON employee.EID = department.EID,
Where CITY = "Vadodara";
-- Right Join
select employee.EID, employee.CITY from employee
Right JOIN department
ON employee.EID = department.EID;
INSERT INTO employee(ENAME, CITY)
values ("Tony", "CD");
-- Full Outer join - Union of Left Outer join and Right Outeer Join
(select * from employee
Left JOIN department
ON employee.EID = department.EID)
UNION
(select * from employee
Right JOIN department
ON employee.EID = department.EID)
select *
from department
Left JOIN employee
ON employee.EID = department.EID;
SELECT *
FROM department
LEFT JOIN employee ON employee.EID = department.EID;