Relational Algebra
Relational Algebra
Relational Algebra
Query optimizer
DBMS
Produce table containing subset of rows of
argument table satisfying condition
condition (relation)
Example:
Person Hobby=‘stamps’(Person)
NOT(Hobby=‘hiking’) (Person)
Hobby‘hiking’ (Person)
Produces
table containing subset of columns of
argument table
attribute list(relation)
Example:
Person
Name,Hobby(Person)
11
Example:
E1 A E1 C1
E2 B E5 C2
E5 C E7 C3
E6 D E8 C4
E8 E E3 C5
E1 A E1 C1
E2 B E5 C2
E5 C E7 C3
E6 D E8 C4
E8 E E3 C5
E1 A E1 C1
E2 B E5 C2
E5 C E7 C3
E6 D E8 C4
E8 E E3 C5
a b c d a b c d
x1 x2 y1 y2 x1 x2 y1 y2
x3 x4 y3 y4 x1 x2 y3 y4
x3 x4 y1 y2
R S x3 x4 y3 y4
R S
Transcript (StudId, CrsCode, Semester, Grade)
• symbol: ⋈ Common
Class_info
ID Address
attribute = common attribute 1 DELHI
2 MUMBAI
3 CHENNAI
Output:
NAME Address
abhi DELHI
adam MUMBAI
alex CHENNAI
Class
ID NAME
Special case of equijoin: 1 abhi
join condition equates all 2 adam
and only those attributes 3 alex
with the same name
4 anu
(condition doesn’t have to
be explicitly stated)
Class_info
duplicate columns
eliminated from the result ID Address
Symbol: ⋈ 1 DELHI
2 MUMBAI
3 CHENNAI
Output:
ID NAME Address
1 abhi DELHI
2 adam MUMBAI
3 alex CHENNAI
Class
ID NAME
1 abhi
Left outer join
includes the common 2 adam
ID NAME ID Address
1 abhi 1 DELHI
2 adam 2 MUMBAI
3 alex 3 CHENNAI
4 anu null null
5 ashish null null
Class
ID NAME
1 abhi
relation ID Address
1 DELHI
Symbol: ⟖
2 MUMBAI
3 CHENNAI
7 NOIDA
8 PANIPAT 32
32
Output:
ID NAME ID Address
1 abhi 1 DELHI
2 adam 2 MUMBAI
3 alex 3 CHENNAI
4 anu null null
5 ashish null null
Class
ID NAME
The full outer join 1 abhi
ID NAME ID Address
1 abhi 1 DELHI
2 adam 2 MUMBAI
3 alex 3 CHENNAI
4 anu null null
5 ashish null null
null null 7 NOIDA
null null 8 PANIPAT
This operator is used to rename the
relations.
The results of relational algebra are also
relations but without any name. The rename
operation allows us to rename the output
relation. 'rename' operation is denoted with
small Greek letter rho ρ.
Symbol: ρ New relation name (Old relation name)
The division operator is used when we
have to evaluate queries which contain
the keyword ALL
Symbol: Relation1 ÷ Relation2
Course_taken
Student_Name Course
Robert Databases Course_required
Robert Programming
Course
Languages
Databases
David Databases
Programming Languages
David Operating Systems
Hannah Programming
Languages
Hannah Databases
Tom Operating Systems
Course_taken ÷ Course_required
Output:
Robert
Hannah
Relational Algebra Operators are critical mathematical
tools used to retrieve queries by describing a sequence
operations on tables or even databases(schema)
involved mathematically. With relational algebra
operators, a query is always composed of a number of
operators, which each in turn are composed of relations
as variables and return an individual abstraction as the
end product. Relational Algebra operations can easily be
translated into SQL commands to retrieve query
results, making it a powerful tool in the hands of any
Database designer, user, and administrator.