Consider the following SQL query
Select distinct
from
where P
For an arbitrary predicate P, this query is equivalent to which of the following relational algebra expressions?
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:
-
The
FROMclause (from $r_1, r_2, e_m$): In SQL, listing multiple relations separated by commas in theFROMclause performs a Cartesian product (cross product) of those relations. -
The
WHEREclause (where P): TheWHEREclause filters the rows based on the predicate . This corresponds to the selection operator () in relational algebra. -
The
SELECT DISTINCTclause (Select distinct $a_1, a_2, e_n$): TheSELECTclause specifies which attributes to project. Since relational algebra operates on sets, the projection operator () automatically eliminates duplicates, matching the behavior ofSELECT DISTINCT.
Combining these steps, the equivalent relational algebra expression is:
Thus, Option A is the correct choice.
Free practice · Your answers on this page are not saved.
