Relational Algebra
Relational Algebra
R
Relational Algebra
SELECT (symbol: σ)
PROJECT (symbol: π)
RENAME (symbol: ρ)
SELECT(RESTRICT)
• SELECT is denoted by the lowercase Greek letter sigma (σ). Sigma is followed by
the condition to be evaluated (called a predicate) as a subscript, and then the relation is listed in
parentheses.
• SELECT referred to as a unary operator because it only uses one table as input. It yields values
for all rows found in the table that satisfy a given condition.
• Comparison operators:<, , , >, =,
• Logical operators:
• ^ “and”, V “or”, ¬ ”not”
EXAMPLE: Display /List all account whose amount is greater
than 8000
• Output
Find the details of the members who were
born on October 21, 1997.
Given relation/table
Details of the members who were born on
21/10/1997.
Given relation/table Answer
Display those Employees who are either Assistant Professors or in the Economics
department
• PROJECT is denoted by the Greek letter pi (π). Pi is followed by the list of attributes to be returned
as subscripts, and then the relation listed in parentheses.
Produce a list of Person showing only the name and hobby.
• Given relation
• EMP
Display the names and departments of the employees
• Give relation
Show the names of all employees working in the CS department:
• Given relation
Display Id & Name, whose Hobbies are either stamps or coins
• p(P, B, C)(Student)
Rename the relation name Project to Pro and
its attributes to P, Q, R.
• p Pro(P, Q, R) (Project)
Relational Algebra Operations From Set Theory
UNION (υ)
INTERSECTION ( )
DIFFERENCE (-)
CARTESIAN PRODUCT ( x )
Union
• UNION combines all rows from two tables, excluding duplicate rows.
• UNION-COMPATIBLE - they have the same degree and the domains of the corresponding
attributes are the same.
Find: R S
• Output
Find names of all customers that have either a
bank account or a loan at the bank
Find names of all customers that have either a
bank account or a loan at the bank
• πcust_name(depositor) ∪ πcust_name(borrower)
List/Display the names of all employees and students
List/Display the names of all employees and students
Student1 Student 2
Sid Sname Saddress
Sid Sname Saddress Sid Sname Saddress
• Given relation
Find THE NAME employees and at the same time students from Relation Employee.
• Given relation
•π Name (Employee) ∩π Name (Student)
Difference
• DIFFERENCE yields all tupples in one table that are not found in the other table.
Find the names of those employees that are not students
• π Name (Employee) — π
Name (Student)
Cartesian- product (X)
Output
Display all the students of department ECE whose fees is greater than
equal to 10000 and belongs to Team other than A.
• Student • Output