in general it is written that select distinct w, x

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

The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+32 votes

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

+43 votes

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.

+8

**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.

+11 votes

+8

yes. but "r has no duplicates" doesn't make sense rt? A relation cannot have duplicates as it is a set of tuples.

0

A relation is defined to be a "SET" of tuples. So, it cannot have same tuples.

Indexing is used for retrieving data from a table. CK can be used for indexing.

Indexing is used for retrieving data from a table. CK can be used for indexing.

- All categories
- General Aptitude 1.6k
- Engineering Mathematics 7.5k
- Digital Logic 3k
- Programming & DS 4.9k
- Algorithms 4.3k
- Theory of Computation 6k
- Compiler Design 2.1k
- Databases 4.2k
- CO & Architecture 3.5k
- Computer Networks 4.2k
- Non GATE 1.4k
- Others 1.5k
- Admissions 584
- Exam Queries 571
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 18

50,115 questions

53,224 answers

184,675 comments

70,473 users