Relational algebra is a procedural language used to define new relations from existing ones without modifying the original relations. It includes unary operations like selection and projection that filter or limit attributes of a single relation. Binary operations like union, set difference, and cartesian product combine two relations - union combines tuples, difference removes tuples in one relation that are in another, and cartesian product concatenates every tuple from one relation with every tuple from the other.
Measures of Central Tendency: Mean, Median and Mode
Presentation
1.
2.
3. Table of contents:
Relational Algebra:
Unary Operation
o Selection
o projection
Binary Operation
o Union
o Set Difference
o Cartesian Product
4. Relational Algebra:
Relational Algebra is a procedural language that processes one
or more relations to define another relation without changing
original relation.
5. 1. Selection Operation:
o Acts like a filter on a relation.
o Return only a certain number of tuples.
o Selects the tuple using a condition.
o Resulting relation has the same degree as the original relation.
Unary Relation:
o Involve only one relation.
6. Examples: Assume a relation EMP has the following tuples:
Name Office Dept Rank
Ahmed 220 CS lecturer
baber 140 Ecno Assistant
Saleem 160 CS Associate
mirza 500 FIn Associate
7. σ dept=‘cs’(EMP)
Result:.
Name Office Dept Rank
Ali 400 CS Assistant
Saleem 160 CS Associate
Question: Select only those employees who are in CS department.
8. 2. Projection:
o Limit the attribute returned from the original relation.
o Projection operator is pi π .
o Resulting table has the same number of tuples as the original.
Example: Assume the EMP relation
Name Office Dept Rank
Ahmed 220 CS lecturer
baber 140 Ecno Assistant
Saleem 160 CS Associate
mirza 500 FIn Associate
9. Question:
Display the names and departments of the all employees working in
CS department:
π name,Dept (σ dept=‘cs’(EMP) )
Result:
Name Dept
Ahmed CS
Saleem CS
10. o Operations which involve pairs of relations.
o Uses two operations as input and produce a new relation as output.
o Types:
1. Union
2. Set Difference
3. Cartesian Product
Binary Operations:
11. o Union operation of two relations combines the tuples of
both relations to produce a third relation.
o Denoted by U.
1.Union:
12. X Y Z
1 A 10
2 B 20
3 C 30
X Y Z
1 A 10
4 D 40
5 E 50
X Y Z
1 A 10
2 B 20
3 C 30
4 D 40
5 E 50
Table A Table B A UNION B
Example: (A U B)
Two relations A and B are combined together by using union operator.
13. 2. Set Difference
o Works on two relations.
o Produces a third relation that contains the tuples that occur
in the first relation but not in second.
14. Example: There are two relations A and B.
X Y Z
1 A 10
2 B 20
3 C 30
X Y Z
1 A 10
4 D 40
5 E 50
X Y Z
2 B 20
3 C 30
X Y Z
4 D 40
5 E 50
Table B A - B B - ATable A
15. 3. Cartesian Product :
o Works on two relations.
o Concatenates every tuple in one relation with every tuple second.
o Also called cross product.
o Product is denoted by a × b.
16. Example:
X Y Z
1 A 10
2 B 20
3 C 30
Table A
X Y Z
1 A 10
4 D 40
5 E 50
X1 Y1 Z1 X2 Y2 Z2
1 A 10 1 A 10
1 A 10 4 D 40
1 A 10 5 E 50
2 B 20 1 A 10
2 B 20 4 D 40
2 B 20 5 E 50
3 C 30 1 A 10
3 C 30 4 D 40
3 C 30 5 A 50
Table B
Table A × B