Given the relations employee (name, salary, dept-no), and department (dept-no,…

2000

Given the relations

employee (name, salary, dept-no), and
department (dept-no, dept-name, address),
Which of the following queries cannot be expressed using the basic relational algebra operations (σ,π,×,⋈,∪,∩,−)?

  1. A.

    Department address of every employee

  2. B.

    Employees whose name is the same as their department name

  3. C.

    The sum of all employees' salaries

  4. D.

    All employees of a given department

Attempted by 223 students.

Show answer & explanation

Correct answer: C

Department address of every employee: Join employee with department on dept-no and project the address.

Example relational algebra:

π_address(employee ⋈_{employee.dept-no = department.dept-no} department)

Employees whose name is the same as their department name: Join employee with department on dept-no, select rows where employee.name = department.dept-name, then project the desired employee attributes.

Example relational algebra:

π_{name, salary, dept-no}(σ_{employee.name = department.dept-name}(employee ⋈_{employee.dept-no = department.dept-no} department))

The sum of all employees' salaries: This cannot be expressed using only the basic relational algebra operators because it requires aggregation (computing a numeric aggregate over a column).

Explanation: Basic relational algebra (selection, projection, Cartesian product, join, union, intersection, difference) manipulates sets of tuples but does not provide grouping or aggregate functions like SUM. To compute the total salary you need an extended operator such as the aggregation γ (e.g., γ_{SUM(salary)}(employee)) or use SQL's SUM() aggregate.

All employees of a given department: This is expressible with basic relational algebra. If you have the department number dept-no = x, select employees with that dept-no and project the employee attributes. If you identify the department by name, join with department first, then select by department name.

Examples:

  • Given dept-no = x: π_{name, salary, dept-no}(σ_{dept-no = x}(employee))

  • Given dept-name = 'D': π_{name, salary, dept-no}(σ_{department.dept-name = 'D'}(employee ⋈_{employee.dept-no = department.dept-no} department))

Summary: The only query here that cannot be expressed with the basic relational algebra operators is the total sum of salaries, because it needs aggregation support.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir