Skip to content
Official PYQ · 2003

GATE CS 2003 Q30 — Relational Model: Relational Algebra

Explain with AI

Consider the following SQL query

Select distinct a1,a2,…,ana_1, a_2, …, a_n

from r1,r2,…,rmr_1, r_2, …, r_m

where P

For an arbitrary predicate P, this query is equivalent to which of the following relational algebra expressions?

Choose one option
View worked solution

Answer: A

To translate the given SQL query into a relational algebra expression, we can map each SQL clause to its corresponding relational algebra operator:

  1. The FROM clause (from $r_1, r_2, e_m$): In SQL, listing multiple relations separated by commas in the FROM clause performs a Cartesian product (cross product) of those relations. Cartesian Product=r1×r2×⋯×rm\text{Cartesian Product} = r_1 \times r_2 \times \dots \times r_m
  2. The WHERE clause (where P): The WHERE clause filters the rows based on the predicate PP. This corresponds to the selection operator (σ\sigma) in relational algebra. σP(r1×r2×⋯×rm)\sigma_P(r_1 \times r_2 \times \dots \times r_m)
  3. The SELECT DISTINCT clause (Select distinct $a_1, a_2, e_n$): The SELECT clause specifies which attributes to project. Since relational algebra operates on sets, the projection operator (Π\Pi) automatically eliminates duplicates, matching the behavior of SELECT DISTINCT. Πa1,a2,…,an(σP(r1×r2×⋯×rm))\Pi_{a_1, a_2, \dots, a_n} \left( \sigma_P \left( r_1 \times r_2 \times \dots \times r_m \right) \right)

Combining these steps, the equivalent relational algebra expression is:

Πa1,a2,…,anσP(r1×r2×⋯×rm)\Pi_{a_1, a_2, \dots, a_n} \sigma_P \left( r_1 \times r_2 \times \dots \times r_m \right)

Thus, Option A is the correct choice.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Relational Model: Relational Algebra questions