GATE / CS ARCHIVE

GATE CSE 2000 / QUESTION 2.25

Projection of a Cartesian product in SQL

Database Management Systems · SQL & Queries · Full GATE CSE 2000 paper

GATE 2000, Q2.25 2 marks · MCQ
Report issue

SQL & Queries

Question 2.25, GATE 2000: For r(w,x) and s(y,z), when is SELECT DISTINCT w,x FROM r,s guaranteed equal to r? Options: r duplicate-free and s nonempty; both duplicate-free; s duplicate-free and r nonempty; equal tuple counts.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Step 1: FROM r,s creates a Cartesian product. If s is nonempty, every row of r appears at least once in that product; projection onto w,x and DISTINCT then returns exactly the distinct rows of r.

Step 2: To preserve SQL bag multiplicities as well, r itself must have no duplicates. No duplicate restriction on s is needed because DISTINCT removes replication.

Hence A. If s is empty, the result is empty even for nonempty r. If r has duplicates, DISTINCT changes it. The other listed conditions do not rule out these failures.

Original paper, page 6