GATE CS 2003 · SQL Queries

MCQ · 1 mark · Problem DBMS-SQL-0148

Consider the following SQL queryselect distinct \(a_1, a_2, \ldots, a_n\) from \(r_1, r_2, \ldots, r_m\) where PFor an arbitrary predicate P, this query is equivalent to which of the following relational algebra expressions?
  1. A
    \(\Pi_{a_1, a_2, \ldots, a_n}\, \sigma_P\,(r_1 \times r_2 \times \cdots \times r_m)\)
  2. B
    \(\Pi_{a_1, a_2, \ldots, a_n}\, \sigma_P\,(r_1 \bowtie r_2 \bowtie \cdots \bowtie r_m)\)
  3. C
    \(\sigma_P\, \Pi_{a_1, a_2, \ldots, a_n}\,(r_1 \times r_2 \times \cdots \times r_m)\)
  4. D
    \(\sigma_P\, \Pi_{a_1, a_2, \ldots, a_n}\,(r_1 \bowtie r_2 \bowtie \cdots \bowtie r_m)\)

Solve it on GATE DA practice →More Relational Model & SQL problems

Show the worked solution\[\boxed{\text{FROM} \to \times,\quad \text{WHERE} \to \sigma_P,\quad \text{SELECT DISTINCT} \to \Pi}\]The FROM list is a Cartesian product, the WHERE clause a selection on it, and SELECT DISTINCT a (duplicate-free) projection applied last.(B) A natural join would also equate the common attributes, which the query does not do.(C), (D) Projecting first can drop attributes that the arbitrary predicate P needs.Answer: A

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com