MALIK AHMED JAMIL
DATABASE SYSTEMS
2420040302-003
MA’AM MASHAL
DEPARTMENT OF COMPUTER SCIENCES
AND SOFTWARE ENGINEERING
WHAT IS NESTED OPERATION IN RELATIONAL ALGEBRA?
Nested Operations:
Nested operations in relational algebra refer to queries that use one operation as an input for
another operation. This is similar to subqueries in SQL. The result of one operation is used as
the operand for another operation.
Example: Finding with AND and OR
Consider a relation (table) named Employees:
Employee ID Name Department Salary Experience
201 Aisha Human Resources 55000 5
202 Bilal Engineering 70000 8
203 Fatima Marketing 60000 4
204 Hassan Engineering 50000 3
205 Zoya Finance 75000 10
Problem: Using AND and OR with Nested Operations
1. Find employees in the Engineering department with a Salary > 60000.
2. Find employees in either the Marketing or Finance departments.
3. Combine both conditions using a nested operation.
Solution in Relational Algebra
1. AND Condition
Find employees in the Engineering department with a Salary > 60000
σ Department= ′ Engineering ′ ∧Salary>60000 (Employees)
Result:
Employee ID Name Department Salary Experience
202 Bilal Engineering 70000 8
OR Condition
Find employees in either the Marketing or Finance departments:
σ Department= ′ Marketing ′ ∨Department= ′ Finance ′ (Employees)
Result:
Employee ID Name Department Salary Experience
203 Fatima Marketing 60000 4
205 Zoya Finance 75000 10
Nested Operation (Combine AND and OR)
Find employees who satisfy either of these conditions:
• Department = 'Engineering' AND Salary > 60000
• Department = 'Marketing' OR Department = 'Finance'
σ Department= ′ Engineering ′ ∧Salary>60000 (Employees)∪
σ Department= ′ Marketing ′ ∨Department= ′ Finance ′ (Employees)
Result:
Employee ID Name Department Salary Experience
202 Bilal Engineering 70000 8
203 Fatima Marketing 60000 4
205 Zoya Finance 75000 10