Relational Algebra
Relational Algebra
Relational Algebra
LANGUAGE
Dr. Thomas Yeboah, Ph.D.
Christian Service University College
Relational Query Languages
• Query languages: Allow manipulation and retrieval of data
from a database.
• Relational Calculus: Lets users describe what they want, rather than
how to compute it. (Non-operational, declarative.)
Relational Algebra
• Relational algebra is the basic set of operations for the
relational model
• Additional operations:
• Intersection, join, division, renaming
Projection
• Deletes attributes that are not in S2
projection list. sid sname rating age
28 yuppy 9 35.0
31 lubber 8 55.5
sname,rating(S2) 44 guppy 5 35.0
58 rusty 10 35.0
sname rating
yuppy 9 age(S 2)
lubber 8 age
guppy 5
35.0
rusty 10
55.5
Selection
• Selects rows that satisfy selection condition.
rating 8(S2)
sid sname rating age
28 yuppy 9 35.0
58 rusty 10 35.0
• Result relation can be the input for another relational algebra
operation! (Operator composition.)
sname,rating( rating 8(S2)) sname rating
yuppy 9
rusty 10
Union, Intersection, Set-
Difference
All of these operations take two input relations, which must be
union-compatible:
• Same number of fields.
• `Corresponding’ fields have the same type.
S1 S2
UNION
S1 S2
S1 S2
S1 R1
S1. sid R1. sid