in general it is written that select distinct w, x

then distinct constraint is applied on only w or on both w, s ??

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.

- r has no duplicates and s is non-empty
- r and s have no duplicates
- s has no duplicates and r is non-empty
- r and s have the same number of tuples

@Arjun Sir,

In option **A, **r has no duplicate also means that r can be empty, which means **Cartesian Product** is **not** possible, then option A becomes invalid. Correct me, if I'm wrong, **PLEASE!**

Best answer

This question is about SQL, in SQL Relations are **MULTISET**, not SET. So, $R$ or $S$ can have duplicated.

Answer: A.

A. If $R$ has duplicates, in that case, due to distinct keyword those duplicates will be eliminated in final result. So, $R$ can not have duplicates. If $S$ is empty $RXS$ becomes empty, so $S$ must be non empty. This is true.

B. Here, assume that S is empty. (No duplicates.) Then R X S will be empty. SO this is false.

C. Same argument as **B.**

D. Assume that $R$ has duplicates. Then Distinct keyword will remove duplicates. So, result of query $!= R$, so This is false.

**Answer:** (a)

**Explanation:**

The query selects all attributes of r. Since we have distinct in query, result can be equal to r only if r doesn’t have duplicates.

If we do not give any attribute on which we want to join two tables, then the queries like above become equivalent to Cartesian product. Cartisian product of two sets will be empty if any of the two sets is empty. So, s should have atleast one record to get all rows of r.

Search GATE Overflow