Relational Algebra
Presenting By:
Kavya l gowda
Deepashree
Shripadma
Introduction to 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 operations to perform this action. SQL Relational algebra query operations
are performed recursively on a relation.
• Relational algebra was introduced by Edgar F. Codd, it is formal or procedural
query language that gives you step by step process to obtain the result of the
query
Basic SQL Relational Algebra Operations
Relational Algebra divided in various groups
Unary Relational Operations Binary Relational Operations
• SELECT (symbol: σ) • JOIN
• PROJECT (symbol: π) • DIVISION
• RENAME (symbol: ρ)
Relational Algebra Operations From Set Theory
• UNION (υ)
• INTERSECTION ( ),
• DIFFERENCE (-)
• CARTESIAN PRODUCT ( x )
Unary Relational Operations
What are Unary Operations in Relational Algebra?
The operations that operate on only one relation are called unary
operations in relational algebra.
The three unary operations in relational algebra are:
• Selection(σ)
• Projection(π)
• Rename(ρ)
Selection Operator (σ)
• The SELECT operation is used for selecting a subset of the tuples according to given
selection condition.
• Sigma(σ) Symbol denotes it.
• It is used as an expression to choose tuples which meet the selection condition.
• Select operation selects tuples that satisfy a given predicate
Syntax :
σ<condition>(R)
Where:
• σ represents the selection operation.
• <condition> is the predicate or condition used to filter the tuples.
• R is the relation (table) from which tuples are selected.
studentTable:
Exampl:
ID Name Age GPA
1 Alice 20 3.5
2 Bob 21 3.2
3 Charlie 19 3.8
4 David 22 3.6
σ(Age >= 21)(student)
ID Name Age GPA
2 Bob 21 3.2
4 David 22 3.6
Projection operation(π)
• The projection eliminates all attributes of the input relation but those mentioned in the
projection list.
• The projection method defines a relation that contains a vertical subset of Relation.
• This helps to extract the values of specified attributes to eliminates duplicate values.
• (pi) symbol is used to choose attributes from a relation.
• This operator helps you to keep specific columns from a relation and discards the other
columns.
Syntax :
π<attribute_list>(R)
Where:
• π represents the projection operation.
• <attribute_list> is a comma-separated list of attributes to be retained in the resulting
relation.
• R is the relation (table) from which attributes are selected.
studentTable:
Example: ID Name Age GPA
1 Alice 20 3.5
2 Bob 21 3.2
3 Charlie 19 3.8 π(Name, GPA)(student)
4 David 22 3.6
Name GPA
Alice 3.5
Bob 3.2
Charlie 3.8
David 3.6
Rename operation(ρ)
The rename operation is used to assign new name to tables and
columns
Syntax to rename column name
ρ<new_attribute_list>(R)
Where:
• ρ represents the rename operation.
• <new_attribute_list> is a comma-separated list of attribute names and their new
names (aliases) enclosed in parentheses.
• R is the relation (table) to which the renaming operation is applied.
studentTable:
Exampl: ID Name Age GPA
1 Alice 20 3.5
2 Bob 21 3.2
3 Charlie 19 3.8
4 David 22 3.6
ρ(Student_ID, Name, Age, GPA)(student)
Student_ID Name Age GPA
1 Alice 20 3.5
2 Bob 21 3.2
3 Charlie 19 3.8
4 David 22 3.6
THANK YOU