in Databases edited by
10,886 views
50 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.

  1. r has no duplicates and s is non-empty
  2. r and s have no duplicates
  3. s has no duplicates and r is non-empty
  4. r and s have the same number of tuples
in Databases edited by
10.9k views

4 Comments

in general it is written that
select distinct w, x 

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

1
distinct constraint apply to both w, x {select distinct w,x IS SAME AS distinct(w,x) } Also Select distinct w, distinct x {INVALID}
6

@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!

0
Why s should be non empty? Else R x S will be empty irrespective of R, so unless R is also it cannot be same as R.

Why r has no duplicates? We have distinct in select. Without distinct in select this condition isn't essential.
0

3 Answers

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

edited by

14 Comments

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.

14
is distinct only on w or both w and x ?
1
@Gate Ranker18

It means distinct pair of (w,x)
3
@Arjun Sir

I think this question is faulty

because it is not join operation. It is cartesian product. After doing cartesian product on 2 tables, we cannot get back 1st table again

plz check it
0

@srestha  mam 

no need for join operation i think

0
but how can you consider "empty set" as "no duplicates" ?

can we do that ?
0
Yes , empty set means nothing is there in the set so there is no chance of having duplicates in the set.(since the set is empty)
1

@Satbir

How, A) could be ans?

Say r has duplicates and r,s has no duplicates due to distinct keyword, then how will it match?

0

Say r has duplicates

in A it is written r has NO duplicates.

 

1
yes, the word given "provided"

That means if r has no duplicates, then only it will be same as r. right?

Actually here options to complete the sentence.
1
yes
0
Hello to all

What if in place of option a) statement, this is written "R is empty"

Then also correct option is a)

Am I correct?
0
Doesn’t the Definition of Candidate Key itself disallow 2 Tuples to Be Same?

I mean if a Relation Has No Proper Subset of Attributes as  Candidate Key, it will have All attributes combined as Candidate Key and so , 2 tuples can’t be same i guess.
0
14 votes
(a)

if s is empty r x s will give empty set, so s cant be empty

7 Comments

reshown by
yes. but "r has no duplicates" doesn't make sense rt? A relation cannot have duplicates as it is a set of tuples.
10
Indexing is not strictly required. But whats the connection between indexing and CK?
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.
0
:O You are from Kerala? :)
0
@Arjun Suresh: Agree with you. r has no duplicates doesn't make sense here.
0
@Arjun, This questions is about SQL. In SQL we allow relations to have duplicates. Check my answer here !
9
edited by

yes In SQL, relation can have duplicate tuples

Relation

           A           B
          1           2
          4           9
          1           2

the above relation, it is valid in SQL but not in Relational Algebra.

12
0 votes

 

Option A would have been correct if the only condition was on S that S should be non empty

Even if R has duplicates, it will exexute correctly

 

 

  1. S is empty
  2. S is non empty
Answer:

Related questions