-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin_L11.sql
More file actions
48 lines (35 loc) · 1.03 KB
/
join_L11.sql
File metadata and controls
48 lines (35 loc) · 1.03 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
create database user;
create table aks(
name varchar(50),usn int primary key);
create table aksh(
name varchar(50),usn int primary key);
create table aksha(
name varchar(50),usn int primary key);
insert into aks (name,usn) values('akshay',4),('jdd',7),('gh',6);
insert into aksh (name,usn) values('akshay',4),('jdd',7),('gh',2),('shdg',5);
insert into aksha (name,usn) values('akshay',4),('jdd',7),('gh',2),('shdg',5),('xcfgyu',6);
select * from aks;
select * from aksh;
select * from aksha;
# inner join
select * from aks inner join aksh on aks.usn=aksh.usn;
# left join
select * from aks left join aksh on aks.usn=aksh.usn;
# right join
select * from aks right join aksh on aks.usn=aksh.usn;
#cross inner join , union
select * from aks
union
select * from aksh;
# union all , prints value as it is
select * from aks
union all
select * from aksh;
# except , it prints all the values of table 1 that r not in table 2
SELECT * FROM aks
EXCEPT
SELECT * FROM aksh;
# rows common in both
select * from aks
intersect
select * from aksh;