Relational Alzebra-1
• RELATIONAL ALGEBRA is a widely used procedural query language
that works on relational model, which takes Relation as input and
generate relation as output.
• The output of these operations is a new relation, which might be
formed from one or more input relations.
• Relational algebra is a procedural query language, it means that it tells
what data to be retrieved and how to be retrieved.
• Unary Relational Operations
• SELECT (symbol: σ)
• PROJECT (symbol: π)
• RENAME (symbol: ρ)
• Binary Relational Algebra Operations From Set Theory
• UNION (υ)
• INTERSECTION (∩ ),
• DIFFERENCE (-)
• CARTESIAN PRODUCT ( x )
• Binary Relational Operations
• JOIN
• DIVISION
SELECT (σ)
• Select operator selects tuples that satisfy a given predicate denoted by σp(r).
• In simple words, Select Operator is denoted by sigma (σ) and it is used to find the
tuples (or rows) in a relation (or table) which satisfy the given condition.
• Unary Operation, defined on single relation.
• It does not change the schema.
SELECT (σ)
• σ Condition/Predicate(Relation/Table name) Table Customer
Select Operator (σ) Example Customer Customer Customer
_Id _Name _City
• Query
C10100 Steve Agra
σ Customer_City="Agra" (CUSTOMER)
Output: C10111 Raghu Agra
C10115 Chaitanya Noida
Customer_Id Customer_Name Customer_City
C10100 Steve Agra C10117 Ajeet Delhi
C10111 Raghu Agra
C10118 Carl Delhi
Project Operator (∏)
• Project operator is denoted by ∏ symbol and it is used to select
desired columns (or attributes) from a table (or relation).
• It change the schema.
• Syntax of Project Operator (∏)
∏ column_name1, column_name2, ...., column_nameN(table_name)
Project Operator (∏) Example
• In this example, we have a table CUSTOMER with three columns, we want to fetch
only two columns of the table, which we can do with the help of Project Operator ∏.
• Table Customer
Customer_Id Customer_Name Customer_City
C10100 Steve Agra
C10111 Raghu Agra
C10115 Chaitanya Noida
C10117 Ajeet Delhi
C10118 Carl Delhi
Query:
∏ Customer_Name, Customer_City (CUSTOMER)
Output:
Customer_Name Customer_City
Steve Agra
Raghu Agra
Chaitanya Noida
Ajeet Delhi
Carl Delhi
Rename (ρ)
• Rename is a unary operation used for renaming attributes of a
relation. It change the schema but not meaning.
• ρa/b(R) will rename the attribute ‘b’ of relation by ‘a’ where
R is a relation
a and b are attribute names
b is an attribute of R
Employee ρ EmployeeName/Name(Employee)
Name (b) EmployeeId EmployeeName
EmployeeId
(a)
Harry 3415
Harry 3415
Sally 2241
Sally 2241
Cartesian product (X)
• Cartesian Product is denoted by X symbol. Lets say we have two
relations R1 and R2 then the cartesian product of these two relations
(R1 X R2) would combine each tuple of first relation R1 with the each
tuple of second relation R2.
• Syntax of Cartesian product (X)
R1 X R2
Cartesian product (X)
Example
if A has ‘n’ tuples and B
has ‘m’ tuples then (A X B)
will have ‘n*m’ tuples.