Professional Documents
Culture Documents
5th Lecture
Relational Algebra
• Relational algebra is a procedural query
language.
• It consist a set of operations that take one two
relations as input and produce a new relation
as their result.
• Relational Algebra is a basis for database
query language.
Operations in Relational Algebra
Operations in Relational Algebra
Relational Algebra in a DBMS
Projection
• A projection operator is used to produce from
a relation R a new relation that has only some
of R’s columns.
R2 = SELECT c (R1)
• C is a condition (as “if” statements) that refers
to attributes of R1.
• R2 is all those tuples of R1 that satisfy C.
Selection
• length 100 (Movies)
A R.B S.B C D
1 2 5 6 7
1 2 5 6 7
1 2 8 9 10
3 4 8 9 10
3 4 11 12 13
3 4 11 12 13
Natural Joins
• Some time we need to join only those tuples
that match in some way, of two relations.
Denoted R ∞ S.
A R.B S.B C D
1 2 2 5 6 A B C D
1 2 2 5 6 1 2 5 6
1 2 4 7 8 3 4 7 8
3 4 4 7 8
3 4 9 10 11
3 4 9 10 11
Theta - Join
• The natural join forces us to pair tuples using one specific
condition.
9 7 8 5 7 10
Combining operations to form Queries
• If we write single operations on one or two
relations as queries, then relational algebra
would not be nearly as useful as it is.