Relational Algebra
By Saidzai
5/19/2005
Relational Algebra
The Relational Algebra is a procedural query
language . A query in Relational Algebra (RA)
has to specify no only what information is
required but also how to extract this
information
Relational algebra
• Relational algebra is a set of operators to
manipulate relations. Each operator of the
relational algebra takes either one or two
relations as its input and produces a new
relation as its output.
Union
• The union of two union-compatible relations
R1 and R2, R1 UNION R2, is the set of all
tuples t belonging to either R1 or R2 or both
• The formal notation for a union operation is U.
• Two relations are union-compatible if they
have the same degree, and the ith attribute
of each is based on the same domain.
Intersection
The intersection of two union-compatible
relations R1 and R2, R1 INTERSECT R2, is the set
of all tuples t belonging to both R1 and R2.
The formal notation for an intersect operation is
∩.
Difference
• The difference between two union-
compatible relations R1 and R2, R1 MINUS
R2, is the set of all tuples t belonging to R1
and not to R2.
• The formal notation for a difference operation
is -
Cartesian product
• The Cartesian product between two relations
R1 and R2, R1 TIMES R2, is the set of all tuples
t such that t is the concatenation of a tuple r
belonging to R1 and a tuple s belonging to R2.
The concatenation of a tuple r = (r1, r2, …, rm)
and a tuple s = (sm+1, sm+2, …, sm+n) is the
tuple t = (r1, r2, …, rm, sm+1, sm+2, …, sm+n).
• The formal notation for a Cartesian product
operation is ×.
Selection
• The select operation selects a subset of tuples
from a relation. It is a unary operator, that is,
it applies on a single relation. The tuples
subset must satisfy a selection condition or
predicate.
• The formal notation for a select operation is:
• σ <select condition> (<relation>)
• <attribute> <comparison operator> <constant
value>/<attribute> [AND/OR/NOT
<attribute> <comparison operator> <constant
value>/<attribute>…]
• The comparison operator can be <, >, <=, >=,
=, <> and it depends on attribute domain or
data type constant value.
Projection
• The project operation builds another relation
by selecting a subset of attributes of an
existing relation. Duplicate tuples from the
resulting relation are eliminated. It is also a
unary operator.
• The formal notation for a project operation is:
• π <attribute list> (<relation>)
• where <attribute list> is the subset attributes
of an existing relation.
• The resulting relation degree is equal with the
number of attributes from <attribute list>
because only those attributes will appear in
the resulting relation.
Join
• The join operation concatenates two relations based
on a joining condition or predicate. The relations
must have at least one common attribute with the
same underlying domain, and on such attributes a
joining condition can be specified.
• The formal notation for a join operation is:
• R <join condition> ►◄S
• where <join condition> is
• <attribute from R> <comparison operator> <
<attribute from S>