Skip to content
Official PYQ · 2000

GATE CS 2000 Q2.25 — Tuple Calculus and SQL

Explain with AI

Given relations r(w, x) and s(y, z) the result of

select distinct w, x 
from r, s 

is guaranteed to be same as r, provided.

Choose one option
View worked solution

Answer: A

To understand when the SQL query is guaranteed to produce the same result as relation rr, let's analyze the operations performed by the query:

SELECT DISTINCT w, x 
FROM r, s
  1. Cartesian Product (FROM r, s): This pairs every tuple in r(w,x)r(w, x) with every tuple in s(y,z)s(y, z).
    • If ss is empty (contains 00 tuples), the Cartesian product rimessr imes s will be empty, resulting in an empty output. Thus, for the output to match rr, ss must be non-empty.
    • If ss is non-empty (contains at least one tuple), then every tuple (wi,xi)∈r(w_i, x_i) \in r will appear at least once in the Cartesian product.
  2. Projection and Duplicate Elimination (SELECT DISTINCT w, x): This projects the attributes w,xw, x and removes any duplicate rows from the final output.
    • If the original relation rr already contained duplicate tuples, the DISTINCT keyword would eliminate them, making the query result different from rr.
    • Therefore, to guarantee the result is identical to rr, rr must have no duplicate tuples.

Combining these two conditions, the query is guaranteed to return the same result as rr if and only if rr has no duplicates and ss is non-empty.

Thus, Option A is the correct choice.

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

Published
Report a correction
Keep exploringMore Tuple Calculus and SQL questions