Lecture 7 - Relational Algebra in DBMS
Lecture 7 - Relational Algebra in DBMS
RELATIONAL
ALGEBRA
Outline of Today’s Class
Relational Algebra in DBMS with Examples
•What is Relational Algebra?
•SELECT(σ)
•Projection(π)
•Union operation (υ)
•Set Difference (-)
•Intersection
•Cartesian product(X)
•Join Operations
•Inner Join:
•Theta Join:
•EQUI join:
•NATURAL JOIN (⋈)
•OUTER JOIN
•Left Outer Join(A B)
•Right Outer Join: ( A B )
•Full Outer Join: ( A B)
What is Relational Algebra?
• Relational algebra is a
widely used
procedural query language. It
collects instances of relations as input
and gives occurrences of relations as
output. It uses various operation to perform
this action.
• Relational algebra operations are performed
recursively on a relation. The output of these
operations is a new relation, which might be
formed from one or more input relations.
Basic Relational Algebra Operations
σp(r)
σ is the predicate
p is prepositional logic
Example 1
σp(r)
σ is the predicate
p is prepositional logic
Example 1
Example 2
Example 3
Example of Projection:
CustomerName Status
Google Active
Amazon Active
Apple Inactive
Alibaba Active
Union operation (υ)
1 1 1 1
1 2 1 3
A ∪ B gives
Table A ∪ B
column 1 column 2
1 1
1 2
1 3
Set Difference (-)
- Symbol denotes it. The result of A - B, is a relation which includes all tuples
that are in A but not in B.
1 2
Intersection
- Symbol denotes it. The result of A - B, is a relation which includes all tuples
that are in A but not in B.
Table A ∩ B
column 1 column 2
1 1
Read other relational algebra stuff