-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path124_concept of sql joins with null and duplicate values.sql
More file actions
121 lines (78 loc) · 2.19 KB
/
124_concept of sql joins with null and duplicate values.sql
File metadata and controls
121 lines (78 loc) · 2.19 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
--concept of joins with null an duplicate values
use sql_challenge;
--Example 1
/*
create table tab1(id1 int);
create table tab2(id2 int);
insert into tab1
values(1),(1),(1)
insert into tab2
values(1),(1)
*/
select * from tab1;
select * from tab2;
--inner join
select * from tab1 inner join tab2 on tab1.id1 = tab2.id2;
--left join
select * from tab1 left join tab2 on tab1.id1 = tab2.id2;
--right join
select * from tab1 right join tab2 on tab1.id1 = tab2.id2;
--full outer join
select * from tab1 full outer join tab2 on tab1.id1 = tab2.id2;
--Example 2
/*
create table tab3(id3 int);
create table tab4(id4 int);
insert into tab3
values(1),(1),(null)
insert into tab4
values(1),(null)
*/
select * from tab3;
select * from tab4;
--inner join
select * from tab3 inner join tab4 on tab3.id3 = tab4.id4;
--left join
select * from tab3 left join tab4 on tab3.id3 = tab4.id4;
--right join
select * from tab3 right join tab4 on tab3.id3 = tab4.id4;
--full outer join
select * from tab3 full outer join tab4 on tab3.id3 = tab4.id4;
--Example 3
/*
create table tab5(id5 int);
create table tab6(id6 int);
insert into tab5
values(1),(null),(2),(2),(4)
insert into tab6
values(1),(null),(3),(4)
*/
select * from tab5;
select * from tab6;
--inner join (2)
select * from tab5 inner join tab6 on tab5.id5 = tab6.id6;
--left join (5)
select * from tab5 left join tab6 on tab5.id5 = tab6.id6;
--right join (4)
select * from tab5 right join tab6 on tab5.id5 = tab6.id6;
--full outer join (7)
select * from tab5 full outer join tab6 on tab5.id5 = tab6.id6;
--Example 4
/*
create table tab7(id7 int);
create table tab8(id8 int);
insert into tab7
values(1),(null),(2),(2),(null)
insert into tab8
values(1),(null),(3),(4),(null),(null),(2)
*/
select * from tab7;
select * from tab8;
--inner join (3)
select * from tab7 inner join tab8 on tab7.id7 = tab8.id8;
--left join (5)
select * from tab7 left join tab8 on tab7.id7 = tab8.id8;
--right join (8)
select * from tab7 right join tab8 on tab7.id7 = tab8.id8;
--full outer join (10)
select * from tab7 full outer join tab8 on tab7.id7 = tab8.id8;