Consider the relational schema given below, where eId of the relation dependent is a foreign key referring to empId of the relation employee. Assume that every employee has at least one associated dependent in the dependent relation.
- employee (empId, empName, empAge)
- dependent (depId, eId, depName, depAge)
Consider the following relational algebra query:
The above query evaluates to the set of empIds of employees whose age is greater than that of
View worked solution
Answer: D
To understand what the relational algebra query evaluates to, let us break it down into two parts separated by the set difference operator ().
1. Left-Hand Side (LHS)
This expression simply retrieves the set of all empIds from the employee relation.
2. Right-Hand Side (RHS)
This expression performs a join between employee and dependent on two conditions:
empId = eId: The dependent belongs to that specific employee.empAge ≤ depAge: The employee's age is less than or equal to their dependent's age.
empIds of all employees who have at least one dependent whose age is greater than or equal to the employee's own age.
3. Set Difference (LHS − RHS)
This subtracts the RHS from the set of all employees. The result contains employees who do not have any dependent with an age greater than or equal to their own age.
Since we are given that every employee has at least one associated dependent, this negation means that for the remaining employees, all of their dependents must be strictly younger than them.
Therefore, the query evaluates to the set of empIds of employees whose age is greater than that of all of his/her dependents.
Free practice · Your answers on this page are not saved.
