RELATIONAL ALGEBRA
AFIF AL MAMUN
RELATIONAL ALGEBRA
Definition: An algebra whose operands are relations or variables that represent
relations.
In database terminology, Relational algebra is a procedural query language.
RELATIONAL ALGEBRA
It consists of:
• SELECTION
• PROJECTION
• DIVISION
• UNION
• INTERSECTION
• PRODUCTS
• NATURAL JOIN
• THETA JOIN
• SET DIFFERENCE
• RENAME
• COMPOSITION etc.
RELATIONAL OPERATORS
SELECTION: σ
PROJECTION: π
DIVISION: ÷
UNION: U
INTERSECTION: ∩
PRODUCTS: x
NATURAL JOIN: ⋈
THETA JOIN: ⋈θ
SET DIFFERENCE: -
RENAME: ρ
SELECTION
Selects tuples from a relation whose attributes meet the selection criteria, which is
normally expressed as a predicate.
Notation − σp(r)
Where σ stands for selection predicate and r stands for relation. p is prepositional
logic formula which may use connectors like and, or, and not. These terms may use
relational operators like − =, ≠, ≥, < , >, ≤.
SELECTION (CONTINUED…)
Example: σrating>8 (S2)
Figure: Sailor Instance Figure: Selection Operation
PROJECTION
It projects column(s) that satisfy a given predicate.
Notation − πCOl1, COl2, …, COLN(r)
Where COL1, COL2 , COLN are attribute names of relation r.
Duplicate rows are automatically eliminated, as relation is a set.
PROJECTION(CONTINUED…)
Example: πsname, rating(S2)
Figure: Sailor Instance Figure: Projection Operation
PROJECTION(CONTINUED…)
Example: πage(S2) [Elimination of Duplication]
Figure: Sailor Instance Figure: Projection Operation
DIVISION
The division is a binary operation that is written as R ÷ S.
Notation − R ÷ S
The result consists of the restrictions of tuples in R to the attribute names unique
to R, i.e., in the header of R but not in the header of S, for which it holds that all their
combinations with tuples in S are present in R.
DIVISION(CONTINUED…)
Example:
=÷
UNION
It performs binary union between two given relations and is defined as −
A ∪ B = { t | t ∈ A or t ∈ B}
Notation − ∪
Figure: A U B
UNION(CONTINUED…)
Example: A U B
U =
INTERSECTION
It performs binary union between two given relations and is defined as −
A ∩ B = { t | t ∈ A and t ∈ B}
Notation − ∩
Figure: A ∩ B
INTERSECTION(CONTINUED…)
Example:
Figure: A ∩ B
∩ =
INTERSECTION(CONTINUED…)
Example:
Figure: A ∩ B
∩ =
PRODUCT
Combines information of two different relations into one.
Notation − r Χ s
Where r and s are relations and their output will be defined as −
r Χ s = { q t | q ∈ r and t ∈ s}
PRODUCT(CONTINUED…)
Example:
Figure: A X B
X =
NATURAL JOIN
Combines information of two different relations into one.
Notation − ⋈
Natural join (⋈) is a binary operator that is written as (R ⋈ S) where R and S are
relations. The result of the natural join is the set of all combinations of tuples in R and
S that are equal on their common attribute names.
NATURAL JOIN(CONTINUED…)
Example:
Figure: Natural Join
THETA JOIN
Theta join combines tuples from different relations provided they satisfy the theta
condition. The join condition is denoted by the symbol θ.
Notation − R1 ⋈θ R2
R1 and R2 are relations having attributes (A1, A2, .., An) and (B1, B2,.. ,Bn) such that
the attributes don’t have anything in common, that is R1 ∩ R2 = Φ.
THETA JOIN(CONTINUED…)
Example:
Figure: Theta Join
SET DIFFERENCE
The result of set difference operation is tuples, which are present in one relation but
are not in the second relation.
Notation − A − B
Finds all the tuples that are present in A but not in B.
SET DIFFERENCE(CONTINUED…)
Example:
Figure: Difference
- =
RENAME
Theta join combines tuples from different relations provided they satisfy the theta
condition. The join condition is denoted by the symbol θ.
Notation − ρ x (A)
Where the result of expression A is saved with name of x.
COMPOSITION
Composition is the type of relational operation where multiple operations are
performed at once.
Example− A=C(m x n)
COMPOSITION(CONTINUED…)
A B C D E
 1
1
1
1
2
2
2
2
 10
10
20
10
10
10
20
10
a
a
b
b
a
a
b
b
 
 
 
 
 
 
 
A B C D E



1
2
2



10
10
20
a
a
b
A B


1
2
m
C D E




10
10
20
10
a
a
b
b
n A=C(m x n) A=C(m x n) [Simplified]
THANK YOU!
REFERENCES
1. https://www.cs.rochester.edu/~nelson/courses/csc_173/relations/algebra.html
2. https://www.tutorialspoint.com/dbms/relational_algebra.htm
3. http://infolab.stanford.edu/~ullman/fcdb/aut07/slides/ra.pdf
4. https://www.slideshare.net/guest20b0b3/relational-algebra-presentation?qid=fea70d5f-1d70-4d6d-88f7-
ca0f6a78d64c&v=&b=&from_search=6
5. https://en.wikipedia.org/wiki/Relational_algebra

Relational Algebra Introduction