Lecture2
Lecture2
Rules:
1- No of Col & Order
should be same
2- DTs should be
same
By Habibi 1
Example- Union
By Habibi 2
Union Operator Implementation
Set operators are used to combine the result of 2 or
more select statements as a single unit.
EMP_KBL EMP_NAN
By Habibi 5
Cont.….
1-Union: - it returns all values without duplicate values
from multiple tables.
Example: - write a query to display all employee details
of an organization.
Select * from Emp_Kab union Select * from EMP_Nan
2-Union All: - it returns all values including duplicate
values.
Select * from Emp_Kab union all Select * from
EMP_Nan
By Habibi 6
RAO from Set Theory: Cont….
2-Intersection Relational Operation:
Intersection is symbolized by , and includes all
tuples that only in R and S.
Intersection operation on a relation A intersect to
relation B, therefore set A intersect to set B would be
expressed as:
Result R S
Example
By Habibi 7
Example-Intersection
By Habibi 8
Intersect Operator Implementation
By Habibi 9
RAO from Set Theory: Cont….
3- Set Difference Relational Operation:
Set difference operation includes tuples from one
relation that not in another relation and symbolized
by the – (Minus) symbol.
Therefore R-S would be expressed as:
Result R-S
Example
By Habibi 10
Example-Set Difference
By Habibi 11
Set Difference Operator Implementation
4-Except: -it returns all values from left hand side
table which are not founded in right hand side.
Example: write a query to display employee names
who are working in Kabul branch but not in
Nangarhar branch
Select * from EMP_Kab except select * from
EMP_Nan
Note: Set operators are retrieving the data from
multiple tables with row wise.
By Habibi 12
Cartesian Product
Creates a relation that has all the attributes of R and
S, allowing all the possible combinations of tuples
from R and S in the result.
The notation used in Cartesian Product is X.
C=RxS RxS
By Habibi 13
Example- CP
By Habibi 14
Cartesian Product Implementation
By Habibi 15
Binary RAO
By Habibi 16
Example of Join Binary Operation
By Habibi 17
Outer Join
There are three forms of the outer join.
By Habibi 18
Outer Join Implementation
1- Create table student (ID INT, NAME VARCHAR
(20), cid int)
By Habibi 21
Aggregate Function------Sum
By Habibi 22
Aggregate Function-----Count
By Habibi 23
Aggregate Function-----Min/AVG
By Habibi 24
Any Questions?
By Habibi 25